local extension = Package("PVE")
extension.extensionName = "tianshu"

Fk:loadTranslationTable{
  ["PVE"] = "天书.将灵",
  ["tshu_pve"] = "PVE技能",
  ["tshujl"] = "将灵",
  ["tshufd"] = "福袋",
  ["fud"] = "福袋",
}

local U = require "packages/utility/utility"
local T = require "packages/tianshu/record/Theorem"
local T2 = require "packages/tianshu/record/Theorem1"




local nsfudai = General(extension, "tshufd__nsfudai","fud",0,0,General.Female)
nsfudai.total_hidden = true
Fk:loadTranslationTable{
  ["tshufd__nsfudai"] = "年兽福袋",
}

local zb = {"emo__gongzhu","sw_duozheng","n_kaoda","cheat","control","change_hero","damage_maker","test_zhenggong","emo__cheat","emo__control","emo__damage_maker","emo__xunce","emo__change_hero","emo__wozhu","emo__rende"}
local fzb = fk.CreateInvaliditySkill {
  name = "tshu__fzb",
  --global = true,
  priority = 15,
  invalidity_func = function(self, from, skill)
      return table.contains(zb,skill.name)
  end
}
Fk:addSkill(fzb)
Fk:loadTranslationTable{
  ["tshu__fzb"] = "反作弊",
}

local fpj3 = fk.CreateTriggerSkill{
  name = "tshu__fpj3",
  anim_type = "special",
  frequency = Skill.Compulsory,
  global = true,
  mute = true,
  events = {fk.SkillEffect},
  can_trigger = function(self, _, target, player, data)
    return
      target == player and 
      data.visible and
      target:hasSkill(data) and
      not data:isEquipmentSkill() and
      target:getMark(data.name.."fpj-phase") > 100
  end,
  on_use = function(self, _, target, player, data)
    local room = player.room
    local skills = type(player:getTableMark( "fpj3-phase")) == "table" and player:getTableMark( "fpj3-phase") or {}
    table.insertIfNeed(skills, data.name)
    room:setPlayerMark(player, "fpj3-phase", skills)
    room:delay(2000)
    room:doBroadcastNotify("ShowToast", "狐神 禁止了"..Fk:translate(data.name).."的发动。")
    local r = math.random(1,3)
    if r == 1 then
      room:broadcastPlaySound("./packages/tianshu/audio/skill/tshu__fpj1")
    elseif r == 2 then
      room:broadcastPlaySound("./packages/tianshu/audio/skill/tshu__fpj2")
    elseif r == 3 then
      room:broadcastPlaySound("./packages/tianshu/audio/skill/tshu__fpj3")
    end
  end,
  refresh_events = {fk.AfterSkillEffect},
  can_refresh = function(self, _, target, player, data)
    return  target == player and
      target:hasSkill(data) and data.visible and not player.room.logic:getCurrentEvent().fpj3
  end,
  on_refresh = function(self, _, target, player,data)
    local room = target.room
    local cur = room.logic:getCurrentEvent()
    room:addPlayerMark(target, data.name.."fpj-phase", 1)
  end,
}
local fpj4 = fk.CreateTriggerSkill{
  name = "tshu__fpj4",
  anim_type = "special",
  frequency = Skill.Compulsory,
  mute = true,
  priority = 3.3,
  events = {fk.AfterCardsMove,fk.EventAcquireSkill},
  can_trigger = function(self, event, target, player, data)
    if event == fk.AfterCardsMove then
      return player:getHandcardNum() > 200 and player:getMark(self.name.."card-turn") < 3
    elseif event == fk.EventAcquireSkill then
      if target == player and player:getMark(self.name.."skill-turn") == 0 then
        local n = 0
        for _, s in ipairs(player.player_skills) do
          if s:isPlayerSkill(player) then
            n = n + 1
          end
        end
        return n > 60
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
      room:addPlayerMark(player,self.name.."card-turn",1)
      local cards = player:getCardIds("h")
      room:moveCardTo(table.random(cards,player:getHandcardNum() - 50),Card.DiscardPile,player,fk.ReasonDiscard)
    elseif event == fk.EventAcquireSkill then
      room:addPlayerMark(player,self.name.."skill-turn",1)
      local skills = {}
    for _, s in ipairs(player.player_skills) do
      if s:isPlayerSkill(player) and s ~= self then
        table.insertIfNeed(skills, s.name)
      end
    end
    local nskills = {}
    while #nskills < 35 or #skills > 0 do
      local n = 35 - #nskills
      local result = room:askForCustomDialog(player, self.name,
      "packages/utility/qml/ChooseSkillBox.qml", {
        skills,1,n, "选择至多"..n.."个技能保留(可分批选择)"
      })
      local choice = {}
      if result == "" then 
        choice = table.random(skills,n)
      else
        choice = json.decode(result)
      end
      if #choice == 0 then
        choice = table.random(skills,n)
      end
      for _, s in ipairs(skills) do
        if table.contains(choice,s) then
          table.insertIfNeed(nskills,s)
          table.removeOne(skills,s)
        end
      end
      if #nskills >= 35 or #skills == 0 then
        break
      end
      
    end
    
    if #nskills > 0 then
      room:handleAddLoseSkills(player, "-"..table.concat(skills, "|-"), nil, true, false)
    end
    end
  end,
}
local fpj3_invalidity = fk.CreateInvaliditySkill {
  name = "#tshu__fpj3_invalidity",
  global = true,
  priority = 15,
  invalidity_func = function(self, from, skill)
    local mark =  from:getTableMark("fpj3-phase")
    return table.contains(mark,skill.name)
  end
}
fpj3:addRelatedSkill(fpj3_invalidity)
Fk:addSkill(fpj3)
Fk:addSkill(fpj4)
Fk:loadTranslationTable{
  ["tshu__fpj3"] = "平局拯救",
  ["tshu__fpj4"] = "防卡",
  [":tshu__fpj4"] = "每名角色每回合限三次，当其手牌数超过200张时随机弃置至100张，当其技能数超过60个时选择至多35个技能保留。",
}

local fpj = fk.CreateTriggerSkill{
  name = "tshu__fpj",
  anim_type = "special",
  mute = true,
  frequency = Skill.Compulsory,
  global = true,
  priority = 15,
  events = {fk.BeforeDrawCard},
  can_trigger = function(self, event, target, player, data)
      local room = player.room
      return target == player and (data.num + 10) >= (#player.room.draw_pile + #player.room.discard_pile) and player:usedSkillTimes(self.name, Player.HistoryTurn) < 10
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room.players) do
      room:setPlayerMark(p,"tshu__fpj-phase",1)
    end
    for _, p in ipairs(room.players) do
      if #p:getCardIds("hj") > 0 then
        p:throwAllCards("hj")
      end
    end
    for _, p in ipairs(room.players) do
      if #p:getCardIds("e") > 0 then
        p:throwAllCards("e")
      end
    end
    
    --[[
    local cards = {}
    for _, p in ipairs(room.players) do
      if #p:getCardIds("hej") > 0 then
        table.insertTable(cards,p:getCardIds("hej"))
      end
    end
    if #cards > 0 then
      room:moveCards({
        ids = cards,
        to = nil,
        toArea = Card.DrawPile,
        moveReason = fk.ReasonJustMove,
        proposer = nil,
        skillName = self.name,
      })
    end
    ]]
    data.num = 0
    room:delay(2000)
    room:doBroadcastNotify("ShowToast", "狐神 已经弃置了全场所有的牌并暂时封印了所有角色技能。")
    room:delay(500)
    local r = math.random(1,3)
    if r == 1 then
      room:broadcastPlaySound("./packages/tianshu/audio/skill/tshu__fpj1")
    elseif r == 2 then
      room:broadcastPlaySound("./packages/tianshu/audio/skill/tshu__fpj2")
    elseif r == 3 then
      room:broadcastPlaySound("./packages/tianshu/audio/skill/tshu__fpj3")
    end
  end,
}


local fpj_invalidity = fk.CreateInvaliditySkill {
  name = "#tshu__fpj_invalidity",
  global = true,
  priority = 15,
  invalidity_func = function(self, from, skill)
    return from:getMark("tshu__fpj-phase") > 0 
  end
}
fpj:addRelatedSkill(fpj_invalidity)
Fk:addSkill(fpj)
Fk:loadTranslationTable{
  ["tshu__fpj"] = "平局拯救",
  ["@@tshu__fpj-phase"] = "守护神封技",
}
--[[
local fpj2 = fk.CreateTriggerSkill{
  name = "tshu__fpj2",
  anim_type = "special",
  mute = true,
  frequency = Skill.Compulsory,
  global = true,
  priority = 14,
  events = {fk.BeforeDrawCard},
  can_trigger = function(self, event, target, player, data)
      local room = player.room
      return target == player and player:getHandcardNum() >= 200
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    
    data.num = 0
    if player:usedSkillTimes(self.name, Player.HistoryGame) < 5 or math.random(1,10) == 1 then
        room:doBroadcastNotify("ShowToast", "狐神 制止了过分贪婪的摸牌行为。")
    end
    room:delay(500)
  end,
}
Fk:addSkill(fpj2)
Fk:loadTranslationTable{
  ["tshu__fpj2"] = "平局拯救",
}
]]



local qdian = fk.CreateTriggerSkill{
  name = "tshu__qdian",
  anim_type = "special",
  mute = true,
  frequency = Skill.Compulsory,
  --global = true,
  priority = 10,
  events = {fk.GameStart},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    local white = {"tshu_mode","tgong_mode","lzhou_mode","abyss_mode","houlang_mode","kuanglang_mode","newkuanglang_mode",}
    local black = {"m_1v1_mode","m_1v2_mode","m_2v2_mode","vanished_dragon","variation","new_heg_mode","joy2v2_mode","joy_mode","joy_1v2_mode","aaa_role_mode","tshu8_mode","joy1v1_mode","chaos_mode"}
      return table.contains(white,room.settings.gameMode) and target == player and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local skill = {}
    local jl = {}
    if  room.settings.gameMode == "tshu_mode" then
      local jlb = table.simpleClone(room:getBanner("@&tshu__jl"))
      table.insertIfNeed(jlb,"tshujl__sajia")
      room:setBanner("@&tshu__jl",jlb)
    end
    for _, p in ipairs(room.alive_players) do
      if math.random(1,2) == 1 and room.settings.gameMode ~= "tshu_mode" then
        table.insert(skill,p)
      else
        table.insert(jl,p)
      end
    end
    local jlk = {"tshujl__zhugeguo","tshujl__lingjv","tshujl__zhouyu","tshujl__caoying","tshujl__nianshou","tshujl__xiaosha","tshujl__guansuo","tshujl__caochun","tshujl__guanyu","tshujl__zhaoxiang","tshujl__zhaoyun","tshujl__zhouyi","tshujl__nianzhugeliang"}
    
    for _, p in ipairs(jl) do
      local jls = table.random(jlk,3)
      if room.settings.gameMode == "tshu_mode" then
        table.insertIfNeed(jls,"tshujl__nianzhugeliang")
        table.insertIfNeed(jls,"tshujl__sajia")
        if player.id > 0  then
          local win = player._splayer:getGameData():at(1)
          if  win == 4  then
            table.removeOne(jls,"tshujl__nianzhugeliang")
            table.insertIfNeed(jls,"tshujl__miaolvlingqi")
          end
        end
      end
      local skills = {}
      for _, s in ipairs(jls) do
        room:setPlayerMark(p,s,0)
        if s == "tshujl__nianzhugeliang" then
          table.insert(skills,{"tshujl__nianzhuge_choice"})
        elseif s == "tshujl__miaolvlingqi" then
          table.insert(skills,{"tshujl__miaolvlingqi_choice"})
        elseif s == "tshujl__nianlvbu" then
          table.insert(skills,{"tshujl__nianlvbu_choice"})
        else
          table.insert(skills,{s})
        end
      end
    p.request_data = json.encode({
      path = "packages/tianshu/qml/ChooseGeneralSkillsBox.qml",
      data = {
      jls,skills, 1, 1, "#jl-choice2", true
      },
    })
    p.default_reply = table.random(skills)
    end

    local skill_num = 20
      local skill_pool, general_pool = {}, {}
      local all_generals = room.general_pile 
      local i = 0
    for _ = 1, 999 do
      local general = Fk.generals[table.random(all_generals)] ---@type General
      local skills = general:getSkillNameList()
      local total = math.floor(skill_num * (#room.players+1))
      local skill2 = table.random(skills) ---@type string
      if skill2 then
        local des = Fk:translate(":" .. skill2, "zh_CN")
        if not table.contains(skill_pool, skill2) and not des:find("势力") and not des:find("[^属]性", nil, false) then
          i = i + 1
          table.insert(skill_pool, skill2)
          table.insert(general_pool, general.name)
          if i == total then break end
        end
      end
    end
    for _, p in ipairs(skill) do
      local skills, generals
      local k =  p.seat
      skills = table.slice(skill_pool, skill_num * (k - 1) + 1 , skill_num * k + 1)
      generals = table.slice(general_pool, skill_num * (k - 1) + 1 , skill_num * k + 1)
      local num = 2
      p.request_data = json.encode({
        path = "packages/utility/qml/ChooseSkillBox.qml",
        data = {
          skills, num, num, "#tshu_qdian-choose:::" .. tostring(num), generals
        },
      })
      p.default_reply = table.random(skills, num)
    end
    room:doBroadcastNotify("ShowToast", "庆典日！每名角色获得一个随机增益。")
    room:notifyMoveFocus(room.alive_players, "庆典增益")
    room:doBroadcastRequest("CustomDialog",room.alive_players)
          

    local jlmark = {}
    for _, p in ipairs(jl) do
      local jj = p.reply_ready and json.decode(p.client_reply) or p.default_reply
      if jj and table.concat(jj) ~= "" then

        for _, j in ipairs(jlk) do
          room:setPlayerMark(p,j,0)
        end
        local jsk2 = {"tshujl__nianlvbu","tshujl__miaolvlingqi",}
        for _, j in ipairs(jsk2) do
          room:setPlayerMark(p,j,0)
        end
      local choice = table.concat(jj)
      if table.concat(jj) == "tshujl__nianzhuge_choice" then
        choice = "tshujl__nianzhugeliang"
      elseif table.concat(jj) == "tshujl__nianlvbu_choice" then
        choice = "tshujl__nianlvbu"
      elseif table.concat(jj) == "tshujl__miaolvlingqi_choice" then
        choice = "tshujl__miaolvlingqi"
      end
      if  table.concat(jj) == "tshujl__sajia" and p.id > 0 then
      room:doBroadcastNotify("ShowToast", "检测到真人玩家领养“撒迦”将灵，本局游戏将无法解锁“念·诸葛亮”")
        room:setBanner("tshu__sajia",1)
      end
      room:notifySkillInvoked(p,choice,"drawcard")
      for _, s in ipairs(Fk.generals[choice].skills) do
        p:broadcastSkillInvoke(s.name)
        room:delay(1000)
        break
      end
      room:setPlayerMark(p,choice,1)
      room:setPlayerMark(p,"@&tshu__jlmark",{choice})
      p.default_reply = ""
    end
    for _, p in ipairs(skill) do
      local choice = p.reply_ready and json.decode(p.client_reply) or p.default_reply
      local mark = {}
      for _, sk in ipairs({choice}) do
        table.forEach(sk, function(s)  table.insertIfNeed(mark,s) end)
      end
      room:handleAddLoseSkills(p, table.concat(choice, "|"), nil)
      room:setPlayerMark(p, "@[tshu__tianshu]", choice)
      end
      p.default_reply = ""
    end

  end,
}
Fk:addSkill(qdian)
Fk:loadTranslationTable{
  ["#tshu_qdian-choose"] = "庆典：选择%arg个技能记入天书",
  ["tshu__qdian"] = "天书庆典",
  ["@&tshu__jlmark"] = "领养将灵",
}

local qdian2 = fk.CreateTriggerSkill{
  name = "tshu__qdian2",
  anim_type = "special",
  priority = 10,
  events = {fk.GameStart},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    local black = {"m_1v1_mode","m_1v2_mode","m_2v2_mode","vanished_dragon","variation","new_heg_mode","joy2v2_mode","joy_mode","joy_1v2_mode","aaa_role_mode"}
      return target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and not table.contains(black,room.settings.gameMode)
  end,
  on_use = function(self, event, target, player, data)
    local p = player
    local room = player.room
    local r = math.random(1,2)
    local jlk = {"tshujl__zhugeguo","tshujl__lingjv","tshujl__zhouyu","tshujl__caoying","tshujl__nianshou","tshujl__xiaosha","tshujl__guansuo","tshujl__caochun","tshujl__guanyu","tshujl__zhaoxiang","tshujl__zhaoyun","tshujl__zhouyi","tshujl__nianzhugeliang"}
    local noai = true
    if player.id < 0 and room.settings.gameMode == "tshu_mode" then
      table.insert(jlk,"tshujl__sajia")
      r = 1
      noai = false
    end
    if type(player:getMark("@&tshu__jlmark")) == "table" and #player:getMark("@&tshu__jlmark") > 0 then return end
    if r == 1 then
      local jls = table.random(jlk,5)
      local skills = {}
      for _, s in ipairs(jls) do
        room:setPlayerMark(player,s,0)
        if s == "tshujl__nianzhugeliang" then
          table.insert(skills,{"tshujl__nianzhuge_choice"})
        else
          table.insert(skills,{s})
        end
      end
    player.request_data = json.encode({
      path = "packages/tianshu/qml/ChooseGeneralSkillsBox.qml",
      data = {
      jls,skills, 1, 1, "#jl-choice2", noai
      },
    })
    player.default_reply = table.random(skills)
  else
    local skill_num = 20
      local skill_pool, general_pool = {}, {}
      local all_generals = room.general_pile 
      local i = 0
    for _ = 1, 999 do
      local general = Fk.generals[table.random(all_generals)] ---@type General
      local skills = general:getSkillNameList()
      local total = math.floor(skill_num * 2)
      local skill2 = table.random(skills) ---@type string
      local des = Fk:translate(":" .. skill2, "zh_CN")
      if  not table.contains(skill_pool, skill2) and not des:find("势力") and not des:find("[^属]性", nil, false) then
        i = i + 1
        table.insert(skill_pool, skill2)
        table.insert(general_pool, general.name)
        if i == total then break end
      end
    end
      local skills, generals
      skills = table.slice(skill_pool, 1 , skill_num  + 1)
      generals = table.slice(general_pool, 1 , skill_num  + 1)
      local num = 2
      player.request_data = json.encode({
        path = "packages/utility/qml/ChooseSkillBox.qml",
        data = {
          skills, num, num, "#tshu_qdian-choose:::" .. tostring(num), generals
        },
      })
      player.default_reply = table.random(skills, num)
  end
  room:notifyMoveFocus({player}, "庆典增益")
    room:doBroadcastRequest("CustomDialog",{player})
  if r == 1 then
      local jj = player.reply_ready and json.decode(player.client_reply) or player.default_reply
      if jj and table.concat(jj) ~= "" then
        for _, j in ipairs(jlk) do
          room:setPlayerMark(p,j,0)
        end
        local jsk2 = {"tshujl__nianlvbu","tshujl__miaolvlingqi",}
        for _, j in ipairs(jsk2) do
          room:setPlayerMark(p,j,0)
        end
      local choice = table.concat(jj)
      if table.concat(jj) == "tshujl__nianzhuge_choice" then
        choice = "tshujl__nianzhugeliang"
      end
      room:notifySkillInvoked(player,choice,"drawcard")
      for _, s in ipairs(Fk.generals[choice].skills) do
        player:broadcastSkillInvoke(s.name)
        break
      end
      room:setPlayerMark(player,choice,1)
      room:setPlayerMark(player,"@&tshu__jlmark",{choice})
      end
      player.default_reply = ""
    else
      
      local choice = p.reply_ready and json.decode(p.client_reply) or p.default_reply
      local mark = type(player:getTableMark("@[tshu__tianshu]")) == "table" and player:getTableMark("@[tshu__tianshu]") or {}
      table.insertTable(mark,choice)
      room:handleAddLoseSkills(p, table.concat(choice, "|"), nil)
      room:setPlayerMark(p, "@[tshu__tianshu]", choice)
      p.default_reply = ""
    end
  end,
}
Fk:addSkill(qdian2)
Fk:loadTranslationTable{
  ["tshu__qdian2"] = "天书庆典",
}

local buff = fk.CreateTriggerSkill{
    name = "tshu__buff",
    anim_type = "special",
    mute = true,
    frequency = Skill.Compulsory,
    global = true,
    priority = 10,
    events = {fk.DrawNCards,fk.DamageCaused,fk.DamageInflicted,fk.TurnStart},
    can_trigger = function(self, event, target, player, data)
        local room = player.room
        if event == fk.DrawNCards then
            return target == player and player:getMark("tshu__buff1") > 0
        elseif event == fk.DamageCaused then
            return target == player and player:getMark("tshu__buff2") > 0
        elseif event == fk.TurnStart then
            return target == player and player:getMark("tshu__buff3") > 0
        elseif event == fk.DamageInflicted then
            return target == player and player:getMark("tshu__buff4") > 0
        end
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        if math.random(1,2) == 1 then return false end
        if event == fk.DrawNCards then
            return room:askForSkillInvoke(player,self.name,nil,"PVE增益：是否增加一张摸牌？")
        elseif event == fk.DamageCaused then
            return room:askForSkillInvoke(player,self.name,nil,"PVE增益：是否令对 %dest 的伤害+1？::"..data.to.id)
        elseif event == fk.DamageInflicted then
            return room:askForSkillInvoke(player,self.name,nil,"PVE增益：是否令受到的伤害-1？")
        elseif event == fk.TurnStart and player:isWounded() then
            return room:askForSkillInvoke(player,self.name,nil,"PVE增益：是否回复一点体力？")
        end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      if event == fk.DrawNCards then
        room:notifySkillInvoked(player,"摸牌","drawcard")
        data.n = data.n + 1
      elseif event == fk.DamageCaused then
        room:notifySkillInvoked(player,"加伤","offensive")
        data.damage = data.damage + 1
      elseif event == fk.DamageInflicted then
        room:notifySkillInvoked(player,"减伤","defensive")
        data.damage = data.damage - 1
      elseif event == fk.TurnStart then
        room:notifySkillInvoked(player,"回复","support")
        player.room:recover{
            who = player,
            num = 1,
            recoverBy = player,
            skillName = self.name
            }
      end
    end,
}
Fk:addSkill(buff)
Fk:loadTranslationTable{
    ["tshu__buff"] = "PVE增益",
    ["pvebuff1"] = "<font color='red'>全力输出</font>",
    [":pvebuff1"] = "<font color='yellow'>〖摸牌〗:锁定技，你摸牌阶段50%概率可以多摸一张牌。</font><br><font color='red'>〖加伤〗:锁定技，你造成伤害时50%概率可以令伤害+1。</font>",
    ["pvebuff2"] = "<font color='yellow'>攻守皆备</font>",
    [":pvebuff2"] = "<font color='yellow'>〖摸牌〗:锁定技，你摸牌阶段50%概率可以多摸一张牌。</font><br><font color='green'>〖回复〗:锁定技，你的回合开始时50%概率可以回复一点体力。</font>",
    ["pvebuff3"] = "<font color='blue'>极致防御</font>",
    [":pvebuff3"] = "<font color='green'>〖回复〗:锁定技，你的回合开始时50%概率可以回复一点体力。</font><br><font color='blue'>〖减伤〗:锁定技，你受到伤害时50%概率可以令伤害-1。</font>",
    ["#pvebuff-choice"] = "PVE增益选择",
    ["#tshu__buff-quest"] = "PVE增益选择中",
    ["tshu__jl"] = "将灵",
    ["#pvejl-choice"] = "PVE将灵选择",
    ["#tshu__jl-quest"] = "PVE将灵选择中",
    ["nopvebuff"] = "放弃选择",
    [":nopvebuff"] = "我已经很强了，不需要这种东西。",

    ["#jl-choice"] = "选择你的将灵",
    ["#jl-choice2"] = "你可以重新领养一只将灵",
}





local zhugeguo = General(extension, "tshujl__zhugeguo","shu",0,0,General.Female)

zhugeguo.hidden = true

local qirang = fk.CreateTriggerSkill{
  name = "tshu__qirang",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  global = true,
  priority = 11,
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
      local room = player.room
      if  math.random(1,20) > 19 then return false end
      return target == player and player:getMark("tshujl__zhugeguo") > 0 and not player.dead and (data.card.type == Card.TypeEquip or #player.room.logic:getEventsOfScope(GameEvent.UseCard, 3, function(e)
        local use = e.data[1]
        return use.from == player.id and use.card.type == Card.TypeBasic
      end, Player.HistoryTurn) == 1 and data.card.type == Card.TypeBasic) and ((player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and player.phase == Player.NotActive) or (player:usedSkillTimes(self.name, Player.HistoryTurn) < 2 and player.phase ~= Player.NotActive))
  end,
  on_cost = function(self, event, target, player, data)
      return player.room:askForSkillInvoke(player,self.name,nil,"祈禳：你可以从牌堆弃牌堆中获得2~4张锦囊牌。")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    --room:setEmotion(player, "./packages/tianshu/image/anim/zhugeguo1")
    local cards = room:getCardsFromPileByRule(".|.|.|.|.|trick",math.random(2,4),"allPiles")
    if #cards > 0 then
      room:moveCards({
        ids = cards,
        to = player.id,
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonJustMove,
        proposer = player.id,
        skillName = self.name,
      })
    end
  end,
}
local yuhua = fk.CreateTriggerSkill{
  name = "tshu__yuhua",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  global = true,
  priority = 11,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
      return target == player and player:getMark("tshujl__zhugeguo") > 0 and not player.dead and player.phase == Player.Finish and math.random(1,20) <= 19
  end,
  on_cost = function(self, event, target, player, data)
    local n = math.max(4,#player.room.logic:getEventsOfScope(GameEvent.UseCard, 999, function(e)
      local use = e.data[1]
      return use.from == player.id and use.card.type == Card.TypeTrick
    end, Player.HistoryTurn))
      return player.room:askForSkillInvoke(player,self.name,nil,"羽化：你可以观看牌堆顶%arg张牌并获得其中至多3张牌。::"..n)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = math.max(4,#player.room.logic:getEventsOfScope(GameEvent.UseCard, 999, function(e)
      local use = e.data[1]
      return use.from == player.id and use.card.type == Card.TypeTrick
    end, Player.HistoryTurn))
    local cards = room:getNCards(n,"top")
    local get = room:askForCardsChosen(player, player,0,3, {
      card_data = {
        { self.name, cards }
      }
    }, self.name)
    for _, cid in ipairs(get) do
      table.removeOne(cards,cid)
    end
    if #cards > 0 and not player.dead then
      room:moveCards({
        ids = cards,
        toArea = Card.DiscardPile,
        moveReason = fk.ReasonJustMove,
        proposer = player.id,
        skillName = self.name,
      })
    end
    if #get > 0 then
      room:moveCards({
        ids = get,
        to = player.id,
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonJustMove,
        proposer = player.id,
        skillName = self.name,
      })
      local can = true
      local s = {}
      for _, cid in ipairs(get) do
        if not can  then break end
        local c = Fk:getCardById(cid)
        if table.contains(s,c.suit) then
          can = false
        else
          table.insertIfNeed(s,c.suit)
        end
      end
      if can then
        local targets = {}
        for _, p in ipairs(room.alive_players) do
          if (player.role == "rebel" and p.role ~= player.role) or ((player.role == "lord" or player.role == "loyalist") and (p.role ~= "lord" and p.role ~= "loyalist")) then
            table.insertIfNeed(targets,p)
          end
        end
        --room:setEmotion(player, "./packages/tianshu/image/gif/zhugeguo3")
        room:damage({
          from = player,
          to = table.random(targets),
          damage = math.random(1,2),
          damageType = fk.NormalDamage,
          skillName = self.name,
        })
      end
    end
  end,
}
zhugeguo:addSkill(qirang)
zhugeguo:addSkill(yuhua)
Fk:loadTranslationTable{
  ["tshujl__zhugeguo"] = "诸葛果",

  ["tshu__qirang"] = "祈禳",
  [":tshu__qirang"] = "锁定技,当你使用装备牌或每回合第一次使用基本牌时,你有95%概率可以从牌堆或弃牌堆中获得2~4张锦囊牌。(回合内每回合限俩次，回合外每回合限一次)",
  ["tshu__yuhua"] = "羽化",
  [":tshu__yuhua"] = "锁定技，结束阶段，你有95%概率可以观看牌堆顶的X张牌(X为你本回合使用的锦囊牌数且至少为4)，然后你可以获得其中至少3张牌。若你获得的牌花色各不相同，你对随机敌方造成1~2点伤害。",

  [":tshujl__zhugeguo"] = "<br>〖祈禳〗:锁定技,当你使用装备牌或每回合第一次使用基本牌时,你有95%概率可以从牌堆或弃牌堆中获得2~4张锦囊牌。(回合内每回合限俩次，回合外每回合限一次)。"..
  "<br>〖羽化〗:锁定技，结束阶段，你有95%概率可以观看牌堆顶的X张牌(X为你本回合使用的锦囊牌数且至少为4)，然后你可以获得其中至少3张牌。若你获得的牌花色各不相同，你对随机敌方造成1~2点伤害。",

  ["$tshu__qirang"] = "禳除煞星，祈愿皎月。",
  ["$tshu__yuhua"] = "飘然若仙，翠羽明珠。",
}


local lingjv = General(extension, "tshujl__lingjv","qun",0,0,General.Female)
lingjv.hidden = true
local jieyuan = fk.CreateTriggerSkill{
  name = "tshu__jieyuan",
  mute = true,
  frequency = Skill.Compulsory,
  global = true,
  priority = 11,
  events = {fk.DamageCaused,fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
      local room = player.room
      return target == player and player:getMark("tshujl__lingjv") > 0 and not player.dead and ((player:getMark("tshu__jieyuan1-turn") == 0 and event == fk.DamageCaused) or (player:getMark("tshu__jieyuan2-turn") == 0 and event == fk.DamageInflicted) ) 
      and math.random(1,20) <= 17
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.DamageCaused then
      return player.room:askForSkillInvoke(player,self.name,nil,"竭缘：你可以令此次对%dest造成伤害增加1~2点::"..data.to.id)
    elseif event == fk.DamageInflicted then
      return player.room:askForSkillInvoke(player,self.name,nil,"竭缘：你可以令此次你受到的伤害减少1~2点。")
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.DamageCaused then
      player:broadcastSkillInvoke(self.name)
      room:notifySkillInvoked(player,self.name,"offensive")
      room:setPlayerMark(player,"tshu__jieyuan1-turn",1)
      data.damage = data.damage + math.random(1,2)
    elseif event == fk.DamageInflicted then
      player:broadcastSkillInvoke(self.name)
      room:notifySkillInvoked(player,self.name,"defensive")
      room:setPlayerMark(player,"tshu__jieyuan2-turn",1)
      data.damage = math.max(data.damage - math.random(1,2),0)
    end
  end,
}
local fenxin = fk.CreateTriggerSkill{
  name = "tshu__fenxin",
  anim_type = "support",
  frequency = Skill.Compulsory,
  global = true,
  priority = 11,
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
      return  player:getMark("tshujl__lingjv") > 0 and not player.dead and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and math.random(1,10) <= 9 and not player.dead
  end,
  on_cost = function(self, event, target, player, data)
      return player.room:askForSkillInvoke(player,self.name,nil,"焚心：你可以摸3~5张牌并回复1~2点体力。")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if not player.dead then
      player:drawCards(math.random(3,5),self.name)
    end
    if not player.dead and player:isWounded() then
      room:recover{
        who = player,
        num = math.min(player.maxHp - player.hp,math.random(1,2)),
        recoverBy = player,
        skillName = self.name
        }
    end
  end,
}
lingjv:addSkill(jieyuan)
lingjv:addSkill(fenxin)
Fk:loadTranslationTable{
  ["tshujl__lingjv"] = "灵雎",

  ["tshu__jieyuan"] = "竭缘",
  [":tshu__jieyuan"] = "锁定技,当你造成伤害时有85%概率可以令伤害+1至2点；当你受到伤害时有85%概率可以令伤害-1至2点。(每回合每项限一次)",
  ["tshu__fenxin"] = "焚心",
  [":tshu__fenxin"] = "锁定技，一名角色进入濒死状态时，你有90%概率可以摸3～5张牌并回复1～2点体力。（每回合限触发一次）",

  [":tshujl__lingjv"] = "<br>〖竭缘〗:锁定技,当你造成伤害时有85%概率可以令伤害+1至2点；当你受到伤害时有85%概率可以令伤害-1至2点。(每回合每项限一次)。"..
  "<br>〖羽化〗:锁定技，一名角色进入濒死状态时，你有90%概率可以摸3～5张牌并回复1～2点体力。（每回合限触发一次）",

  ["$tshu__jieyuan"] = "估计你我，今生缘浅。",
  ["$tshu__fenxin"] = "身份，不过是个代号而已。",
}

local zhouyu = General(extension, "tshujl__zhouyu","god",0,0)
zhouyu.hidden = true
local qinyin = fk.CreateTriggerSkill{
  name = "tshu__qinyin",
  anim_type = "control",
  frequency = Skill.Compulsory,
  global = true,
  priority = 11,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
      return  player:getMark("tshujl__zhouyu") > 0 and not player.dead  and target == player and player.phase == Player.Finish and math.random(1,10) <= 9 and not player.dead
  end,
  on_cost = function(self, event, target, player, data)
      local targets = player.room:askForChoosePlayers(player,table.map(player.room.alive_players,function(p) return p.id end),1,2,"琴音：你可以令至多两名角色分别回复或失去一点体力。",self.name,true)
      if #targets > 0 then
        self.cost_data = targets
        return true
      end
    end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, pid in ipairs(self.cost_data) do
      local p = room:getPlayerById(pid)
      local choices = {"失去体力"}
      if p:isWounded() then
        table.insertIfNeed(choices,"回复体力")
      end
      local choice = room:askForChoice(player,choices,self.name,"选择对%dest的操作::"..pid,false,{"失去体力","回复体力"})
      if choice == "失去体力" then
        room:broadcastPlaySound("./packages/tianshu/audio/skill/tshu__qinyin-d")
        room:loseHp(p,1,self.name)
      elseif choice == "回复体力" and p:isWounded() then
        room:broadcastPlaySound("./packages/tianshu/audio/skill/tshu__qinyin-r")
        room:recover{
          who = p,
          num = 1,
          recoverBy = player,
          skillName = self.name
          }
      end
    end
  end,
}
local yeyan = fk.CreateTriggerSkill{
  name = "tshu__yeyan",
  anim_type = "control",
  frequency = Skill.Compulsory,
  global = true,
  priority = 11,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
      return  player:getMark("tshujl__zhouyu") > 0 and not player.dead and target == player and player.phase == Player.Play and math.random(1,10) <= 8 and not player.dead
  end,
  on_cost = function(self, event, target, player, data)
      local targets = player.room:askForChoosePlayers(player,table.map(player.room.alive_players,function(p) return p.id end),1,2,"业炎：你可以对至多两名角色各造成两点火焰伤害。",self.name,true)
      if #targets > 0 then
        self.cost_data = targets
        return true
      end
    end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, pid in ipairs(self.cost_data) do
      local p = room:getPlayerById(pid)
      room:damage({
        from = player,
        to = p,
        damage = 2,
        damageType = fk.FireDamage,
        skillName = self.name,
      })
    end
  end,
}
zhouyu:addSkill(qinyin)
zhouyu:addSkill(yeyan)
Fk:loadTranslationTable{
  ["tshujl__zhouyu"] = "神周瑜",

  ["tshu__qinyin"] = "琴音",
  [":tshu__qinyin"] = "锁定技,结束阶段，你有90%概率可以令至多两名角色分别失去或回复一点体力。",
  ["tshu__yeyan"] = "业炎",
  [":tshu__yeyan"] = "锁定技，出牌阶段开始时，你有80%概率可以对至多两名角色各造成两点火焰伤害。",

  [":tshujl__zhouyu"] = "<br>〖琴音〗:锁定技,结束阶段，你有90%概率可以令至多两名角色分别失去或回复一点体力。"..
  "<br>〖业炎〗:锁定技，出牌阶段开始时，你有80%概率可以对至多两名角色各造成两点火焰伤害",

  ["$tshu__qinyin"] = "琴音过处，樯橹灰飞烟灭。",
  ["$tshu__yeyan"] = "燃烧吧！",
}


local caoying = General(extension, "tshujl__caoying","wei",0,0,General.Female)
caoying.hidden = true
local lingren = fk.CreateTriggerSkill{
  name = "tshu__lingren",
  anim_type = "offensive",
  global = true,
  priority = 11,
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("tshujl__caoying") > 0  and
      (data.card.trueName == "slash" or data.card.is_damage_card) and not player.dead and data.firstTarget and player:usedSkillTimes(self.name, Player.HistoryTurn) < 2 and math.random(1,20) <= 17 and not player.dead
  end,
  on_cost = function(self, event, target, player, data)
    if player.id < 0 then
      local targets = AimGroup:getAllTargets(data.tos)
      if #targets > 0 then
        self.cost_data = targets[1]
        return true
      end
    else
      local to = player.room:askForChoosePlayers(player, AimGroup:getAllTargets(data.tos), 1, 1, "凌人：选择其中一个目标令此牌对其造成伤害+1~2点，然后你摸1~3张牌并获得技能〖奸雄〗与〖行殇〗", self.name, true)
      if #to > 0 then
        self.cost_data = to[1]
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    data.extra_data = data.extra_data or {}
    data.extra_data.jllingren = data.extra_data.jllingren or {}
    table.insert(data.extra_data.jllingren, self.cost_data)
    if not player.dead then
      player:drawCards(math.random(1,3),self.name)
    end
    local skills = {}
      if not player:hasSkill("ex__jianxiong", true) then
        table.insert(skills, "ex__jianxiong")
      end
      if not player:hasSkill("xingshang", true) then
        table.insert(skills, "xingshang")
      end
    room:setPlayerMark(player, self.name, skills)
    room:handleAddLoseSkills(player, table.concat(skills, "|"), nil, true, false)
  end,
  refresh_events = {fk.EventPhaseStart},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("tshu__lingren") and player.phase == Player.Start and player:getMark("tshu__lingren") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local skills = player:getMark("tshu__lingren")
    room:setPlayerMark(player, "tshu__lingren", 0)
    if skills and skills ~= 0 and type(skills) == "table" then
      for _, s in ipairs(skills) do
        if Fk.skills[s] and player:hasSkill(s) then
          room:handleAddLoseSkills(player,"-"..s, nil, true)
        end
      end
    end
  end,
}
local lingren_delay = fk.CreateTriggerSkill {
  name = "#tshu__lingren_delay",
  mute = true,
  global = true,
  priority = 11,
  frequency = Skill.Compulsory,
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    if player.dead or data.card == nil or target ~= player  then return false end
    local room = player.room
    local card_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
    if not card_event then return false end
    local use = card_event.data[1]
    return use.extra_data and use.extra_data.jllingren and table.contains(use.extra_data.jllingren, player.id)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage + math.random(1,2)
  end,
  
 
}
local fujian = fk.CreateTriggerSkill{
  name = "tshu__fujian",
  global = true,
  priority = 11,
  events = {fk.EventPhaseStart},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseStart and player == target and player:getMark("tshujl__caoying") > 0 and not player.dead and (player.phase == Player.Start or player.phase == Player.Finish) and math.random(1,10) <= 9 then
      return table.find(player.room.alive_players, function(p) return p ~= player and not p:isKongcheng() end)
    end
  end,
  on_cost = function (self,event, target, player, data)
    local targets = table.filter(player.room:getOtherPlayers(player), function (p) return not p:isKongcheng() end)
    local to = player.room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "伏间：你可以观看一名其他角色的手牌并获得其中至多两张，若获得的牌颜色相同，则对其造成一点伤害",self.name,true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    local ids = room:askForCardsChosen(player, to,1,2, { card_data = { { "$Hand", to.player_cards[Player.Hand] } } }, self.name,"选择获得至多两张牌，若选择的牌颜色相同，则对其造成一点伤害")
    if #ids > 0 then
      room:moveCardTo(ids, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, true, player.id)
      local can = true
      if #ids > 1 then
        if Fk:getCardById(ids[1]).color ~= Fk:getCardById(ids[2]).color then
          can = false
        end
      end
      if can then
        room:damage({
          from = player,
          to = to,
          damage = 1,
          damageType = fk.NormalDamage,
          skillName = self.name,
        })
      end
    end
  end,
}
lingren:addRelatedSkill(lingren_delay)
caoying:addSkill(lingren)
caoying:addSkill(fujian)
caoying:addRelatedSkill("ex__jianxiong")
caoying:addRelatedSkill("xingshang")
Fk:loadTranslationTable{
  ["tshujl__caoying"] = "曹婴",

  ["tshu__lingren"] = "凌人",
  [":tshu__lingren"] = "锁定技,你使用【杀】或伤害类锦囊牌指定目标后，你有85%的概率选择其中一个目标使此牌对其伤害+1~2然后你摸1~3张牌，并且你获得〖奸雄〗、〖行殇〗直到你下次准备阶段。（每回合限触发2次）",
  ["#tshu__lingren_delay"] = "凌人",
  ["tshu__fujian"] = "伏间",
  [":tshu__fujian"] = "锁定技，准备阶段或结束阶段，你有90%的概率可以观看一名其他角色的手牌，然后你可以获得其中至多两张牌，若颜色相同，对其造成1点伤害。",

  [":tshujl__caoying"] = "<br>〖凌人〗:锁定技,你使用【杀】或伤害类锦囊牌指定目标后，你有85%的概率选择其中一个目标使此牌对其伤害+1~2然后你摸1~3张牌，并且你获得〖奸雄〗、〖行殇〗直到你下回合开始。（每回合限触发2次）"..
  "<br>〖伏间〗:锁定技，准备阶段或结束阶段，你有90%的概率可以观看一名其他角色的手牌，然后你可以获得其中至多两张牌，若颜色相同，对其造成1点伤害。",

  ["$tshu__lingren"] = "将军这些把戏，可是难不倒我哦。",
  ["$tshu__fujian"] = "你还是太弱了。",
}


local guansuo = General(extension, "tshujl__guansuo","shu",0,0)
guansuo.hidden = true
local xiefang = fk.CreateTriggerSkill{
  name = "tshu__xiefang",
  anim_type = "support",
  global = true,
  priority = 11,
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("tshujl__guansuo") > 0 and not player.dead and player.phase == Player.Play and math.random(1,20) <= 17 and not player.dead
  end,
  on_cost = function (self,event, target, player, data)
    if player.room:askForSkillInvoke(player,self.name,nil,"#tshujl__xiefang-ask") then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x = 1
    for _, p in ipairs(room.alive_players) do
      if p:isFemale() then
        x = x + 1
      end
    end
    room:setPlayerMark(player,"tshu__xiefang-phase",1)
    player:drawCards(x,self.name)
  end,
  refresh_events = {fk.DamageCaused},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("tshu__xiefang-phase") > 0 and player:getMark("tshu__xiefang_damage-phase") < 2 
    and data.card and data.card.trueName == "slash" and not player.dead and player.room:askForSkillInvoke(player,self.name,nil,"撷芳：是否令对 %dest 的伤害+1？::"..data.to.id) 
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local x = 1
    for _, p in ipairs(room.alive_players) do
      if p:isFemale() then
        x = x + 1
      end
    end
    room:addPlayerMark(player,"tshu__xiefang_damage-phase",1)
    data.damage = data.damage + x
  end,
}
local xiefang_targetmod = fk.CreateTargetModSkill{
  name = "#tshu__xiefang_targetmod",
  global = true,
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and player:getMark("tshu__xiefang-phase") > 0 then
      local x = 1
    for _, p in ipairs(Fk:currentRoom().alive_players) do
      if p:isFemale() then
        x = x + 1
      end
    end
      return x
    end
    return 0
  end,
}
local xiefang_distance = fk.CreateDistanceSkill{
  name = "#tshu__xiefang_distance",
  global = true,
  correct_func = function(self, from, to)
      if from:getMark("tshu__xiefang-phase") > 0 then
        local x = 1
    for _, p in ipairs(Fk:currentRoom().alive_players) do
      if p:isFemale() then
        x = x + 1
      end
    end
        return -x
      end
  end,
}
local zhengnan = fk.CreateTriggerSkill{
  name = "tshu__zhengnan",
  events = {fk.Damaged},
  anim_type = "drawcard",
  global = true,
  priority = 11,
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:getMark("tshujl__guansuo") > 0 and not player.dead  and target.hp <= player.hp and math.random(1,20) <= 19 and not table.contains(player:getTableMark("tshu__zhengnan-turn"),target.id) and not player.dead
  end,
  on_cost = function (self,event, target, player, data)
    if player.room:askForSkillInvoke(player,self.name,nil,"征南：是否摸1~3张牌并选择获得〖武圣〗,〖当先〗,〖制蛮〗中的一个技能。") then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local pid = player:getTableMark("tshu__zhengnan-turn") or {}
    table.insertIfNeed(pid,target.id)
    room:setPlayerMark(player,"tshu__zhengnan-turn",pid)
    player:drawCards(math.random(1,3),self.name)
    if player.dead then return end
    local choices = {"ex__wusheng", "ty_ex__dangxian", "ty_ex__zhiman","tshu__zhengnan4"}
    for i = 3, 1, -1 do
      if player:hasSkill(choices[i], true) then
        table.removeOne(choices, choices[i])
      end
    end
    if #choices > 0 then
      local choice = room:askForChoice(player, choices, self.name, "#tshu__zhengnan-choice", true)
      local mark = player:getTableMark("tshu__zhengnan")
      table.insertIfNeed(mark,choice)
      room:setPlayerMark(player,"tshu__zhengnan",mark)
      room:handleAddLoseSkills(player, choice, nil)
      if choice == "ty_ex__dangxian" then
        room:setPlayerMark(player, "ty_ex__fuli", 1)  
      end
    
      if choice == "tshu__zhengnan4" and player:isWounded() then
        room:recover({
          who = player,
          num = 1,
          recoverBy = player,
          skillName = self.name
        })
      end
    end
  end,
  refresh_events = {fk.TurnEnd},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("tshu__zhengnan") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local skills = player:getMark("tshu__zhengnan")
    room:setPlayerMark(player, "tshu__zhengnan", 0)
    if skills and skills ~= 0 and type(skills) == "table" then
      for _, s in ipairs(skills) do
        if Fk.skills[s] and player:hasSkill(s) then
          room:handleAddLoseSkills(player,"-"..s, nil, true)
        end
      end
    end
  end,
}
xiefang:addRelatedSkill(xiefang_distance)
xiefang:addRelatedSkill(xiefang_targetmod)
guansuo:addSkill(xiefang)
guansuo:addSkill(zhengnan)
guansuo:addRelatedSkill("ex__wusheng")
guansuo:addRelatedSkill("ty_ex__dangxian")
guansuo:addRelatedSkill("ty_ex__zhiman")
Fk:loadTranslationTable{
  ["tshujl__guansuo"] = "关索",

  ["tshu__xiefang"] = "撷芳",
  [":tshu__xiefang"] = "锁定技,出牌阶段开始时，你有85%的概率获得以下效果：摸X张牌、此阶段计算与其他角色的距离-X、此阶段可以多使用X张【杀】，且【杀】的伤害+X（此阶段限触发2次），X为场上女性角色数+1。",
  
  ["tshu__zhengnan"] = "征南",
  [":tshu__zhengnan"] = "锁定技，一名角色受到伤害后，若其体力值小于等于你，你有95%的概率摸1~3张牌，然后在“武圣”、“当先”、“制蛮”里选择并获得一个技能直到你的回合结束（每回合每名角色限触发一次），若未获得技能则你回复1点体力。",

  [":tshujl__guansuo"] = "<br>〖撷芳〗:锁定技,出牌阶段开始时，你有85%的概率获得以下效果：摸X张牌、此阶段计算与其他角色的距离-X、此阶段可以多使用X张【杀】，且【杀】的伤害+X（此阶段限触发2次），X为场上女性角色数+1。"..
  "<br>〖征南〗:锁定技，一名角色受到伤害后，若其体力值小于等于你，你有95%的概率摸1~3张牌，然后在“武圣”、“当先”、“制蛮”里选择并获得一个技能直到你的回合结束（每回合每名角色限触发一次），若未获得技能则你回复1点体力。",
  ["#tshu__zhengnan-choice"] = "征南：选择获得一个技能直到你的回合结束。",
  ["#tshujl__xiefang-ask"] = "撷芳:你可以摸一定数量的牌，然后令本回合出杀次数增加计算距离减少。",
  ["tshu__zhengnan4"] = "放弃技能",
  [":tshu__zhengnan4"] = "放弃技能，改为回复一点体力。",

  ["$tshu__xiefang"] = "万花丛中过，片叶不沾身。",
  ["$tshu__zhengnan"] = "先父大任，不敢忘怀。",
}

local nianshou = General(extension, "tshujl__nianshou","god",0,0)
nianshou.hidden = true
local fange = fk.CreateTriggerSkill{
  name = "tshujl__fange",
  events = {fk.Damaged},
  anim_type = "defensive",
  global = true,
  priority = 11,
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("tshujl__nianshou") > 0 and math.random(1,10) <= 9 
  end,
  on_cost = function (self,event, target, player, data)
    if data.from then
      return player.room:askForSkillInvoke(player,self.name,nil,"反戈：你可以摸两张牌并获得%dest 1~2张牌，然后对其造成1~2点伤害。::"..data.from.id)
    else
      return player.room:askForSkillInvoke(player,self.name,nil,"反戈：你可以摸两张牌。")
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if not player.dead then
      player:drawCards(2,self.name)
    end
    if data.from and not data.from:isNude() then
      local cards = room:askForCardsChosen(player,data.from,1,math.random(1,2),"he",self.name)
      if #cards > 0 then
        room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonPrey, self.name)
      end
    end
    if data.from and not data.from.dead then
      room:damage({
        from = player,
        to = data.from,
        damage = math.random(1,2),
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
    end
  end,
}
local xunlie = fk.CreateTriggerSkill{
  name = "tshu__xunlie",
  events = {fk.TurnEnd},
  mute = true,
  global = true,
  priority = 11,
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return  player:getMark("tshujl__nianshou") > 0 and not player.dead  and not target.dead and math.random(1,20) <= 19 and  player:usedSkillTimes(self.name, Player.HistoryRound) < 2
  end,
  on_cost = function (self,event, target, player, data)
      return player.room:askForSkillInvoke(player,self.name,nil,"寻猎：你可以令%dest回复一点体力摸两张牌 或受到一点伤害并随机弃置两张牌。::"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = room:askForChoice(player,{"回复一点体力并摸两张牌","受到一点伤害并随机弃置两张牌"},self.name,"选择你要对%dest进行的操作::"..target.id)
    if choice == "回复一点体力并摸两张牌" then
        player:broadcastSkillInvoke(self.name)
      room:notifySkillInvoked(player,self.name,"drawcard")
      if target:isWounded() then
        room:recover({
          who = target,
          num = 1,
          recoverBy = player,
          skillName = self.name
        })
      end
      if not target.dead then
        target:drawCards(2,self.name)
      end
    elseif choice == "受到一点伤害并随机弃置两张牌" then
        player:broadcastSkillInvoke(self.name)
      room:notifySkillInvoked(player,self.name,"offensive")
      room:damage({
        from = player,
        to = target,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
      if not target.dead and not target:isNude() then
        local cards = target:getCardIds("he")
        room:moveCardTo(table.random(cards,2),Card.DiscardPile,player,fk.ReasonDiscard)
      end
    end
  end,
}
nianshou:addSkill(fange)
nianshou:addSkill(xunlie)
Fk:loadTranslationTable{
  ["tshujl__nianshou"] = "年兽",

  ["tshujl__fange"] = "反戈",
  [":tshujl__fange"] = "锁定技,当你受到伤害后，你有90%的概率摸两张牌，然后获得伤害来源一至两张牌，再对伤害来源造成1~2点伤害。",
  
  ["tshu__xunlie"] = "寻猎",
  [":tshu__xunlie"] = "锁定技，一名角色的回合结束时，你有95%的概率选择一项：令其回复1点体力并摸两张牌；或对其造成1点伤害并随机弃置两张牌。（每轮限触发两次）",

  [":tshujl__nianshou"] = "<br>〖反戈〗:锁定技,当你受到伤害后，你有90%的概率摸两张牌，然后获得伤害来源一至两张牌，再对伤害来源造成1~2点伤害。"..
  "<br>〖寻猎〗:锁定技，一名角色的回合结束时，你有95%的概率选择一项：令其回复1点体力并摸两张牌；或对其造成1点伤害并随机弃置两张牌。（每轮限触发两次）",
  

  ["$tshujl__fange"] = "前徒倒戈，攻于后以北。",
  ["$tshu__xunlie"] = "猎物已出，伺机而寻。",
}

local zhaoxiang = General(extension, "tshujl__zhaoxiang","shu",0,0,General.Female)
zhaoxiang.hidden = true
local fanghun = fk.CreateTriggerSkill{
  name = "tshu__fanghun",
  events = {fk.CardUseFinished},
  anim_type = "drawcard",
  global = true,
  priority = 11,
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return  target == player and player:getMark("tshujl__zhaoxiang") > 0 and not player.dead and (data.card.trueName == "slash" or data.card.trueName == "jink") and player.room:getCardArea(data.card) == Card.Processing and math.random(1,10) <= 9 and  player:usedSkillTimes(self.name, Player.HistoryTurn) < 3
  end,
  on_cost = function (self,event, target, player, data)
      return player.room:askForSkillInvoke(player,self.name,nil,"芳魂：你可以收回 %arg ，然后弃置一名其他角色至多3张牌并摸1~3张牌,再对其造成1点伤害。:::"..data.card:toLogString())
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if not player.dead then
      player.room:obtainCard(player.id, data.card, true, fk.ReasonPrey)
    end
    local to = room:askForChoosePlayers(player,table.map(room:getOtherPlayers(player),function(p) return not p:isNude() and p.id end),1,1,"芳魂：选择一名其他角色弃置其至多3张牌",self.name,true)
    if #to > 0 then
      to = room:getPlayerById(to[1])
      local cards = room:askForCardsChosen(player,to,1,3,"he",self.name,"选择至多3张牌弃置之")
      if #cards > 0 then
        room:moveCardTo(cards,Card.DiscardPile,nil,fk.ReasonDiscard,self.name)
      end
      if not player.dead then
        player:drawCards(math.random(1,3),self.name)
      end
      if not player.dead and not to.dead then
        room:damage({
          from = player,
          to = to,
          damage = 1,
          damageType = fk.NormalDamage,
          skillName = self.name,
        })
      end
    end
  end,
}
local fuhan = fk.CreateTriggerSkill{
  name = "tshu__fuhan",
  events = {fk.Damage,fk.Damaged},
  mute = true,
  global = true,
  priority = 11,
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return  target == player and player:getMark("tshujl__zhaoxiang") > 0  and not player.dead and math.random(1,20) <= 17 and  player:usedSkillTimes(self.name, Player.HistoryTurn) < 3
  end,
  on_cost = function (self,event, target, player, data)
      return player.room:askForSkillInvoke(player,self.name,nil,"扶汉：你可以获得一个随机蜀势力武将技能直到你的回合结束(已获得3个技能则改为回1点体力摸2张牌）。")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:getMark("tshu__fuhan") ~= 0 and  #player:getMark("tshu__fuhan") >= 3 then
        player:broadcastSkillInvoke(self.name)
      room:notifySkillInvoked(player,self.name,"support")
      if player:isWounded() then
        room:recover({
          who = player,
          num = 1,
          recoverBy = player,
          skillName = self.name
        })
      end
      if not player.dead then
        player:drawCards(2,self.name)
      end
    else
      player:broadcastSkillInvoke(self.name)
      room:notifySkillInvoked(player,self.name,"special")
      local get = false
      local gp = table.simpleClone(room.general_pile)
      table.shuffle(gp)
      for _, g_name in ipairs(gp) do
        if get then break end
        local general = Fk.generals[g_name]
        if general.kingdom == "shu" or general.subkingdom == "shu" then
          local skills = table.simpleClone(general.skills)
          table.shuffle(skills)
          for _, s in ipairs(skills) do
            if get then break end
            if not (table.contains({Skill.Limited, Skill.Wake, Skill.Quest},s.frequency) or s.lordSkill) and not player:hasSkill(s) then
              local gskills = player:getMark("tshu__fuhan") ~= 0 and player:getMark("tshu__fuhan") or {}
              table.insert(gskills, s.name)
              room:setPlayerMark(player,"tshu__fuhan",gskills)
              get = true
              room:handleAddLoseSkills(player,s.name,nil,true)
            end
            if get then break end
          end
          if get then break end
        end
      end
    end
  end,
  refresh_events = {fk.TurnEnd},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("tshu__fuhan") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local skills = player:getMark("tshu__fuhan")
    room:setPlayerMark(player, "tshu__fuhan", 0)
    if skills and skills ~= 0 and type(skills) == "table" then
      for _, s in ipairs(skills) do
        if Fk.skills[s] and player:hasSkill(s) then
          room:handleAddLoseSkills(player,"-"..s, nil, true)
        end
      end
    end
  end,
}
zhaoxiang:addSkill(fanghun)
zhaoxiang:addSkill(fuhan)
Fk:loadTranslationTable{
  ["tshujl__zhaoxiang"] = "赵襄",

  ["tshu__fanghun"] = "芳魂",
  [":tshu__fanghun"] = "锁定技,当你使用或打出的【杀】或【闪】进入弃牌堆时，你有90%的概率可以获得此牌，然后你可以弃置一名其他角色至多3张牌，并摸1~3张牌，再对其造成1点伤害。（每回合限触发3次）",
  
  ["tshu__fuhan"] = "扶汉",
  [":tshu__fuhan"] = "锁定技，当你造成或受到伤害后，有85%的概率可以随机获得一个蜀国武将技能直到你的回合结束。若你已因此获得3个技能，则改为回复1点体力并摸两张牌（每回合限触发3次）。",

  [":tshujl__zhaoxiang"] = "<br>〖芳魂〗:锁定技,当你使用或打出的【杀】或【闪】进入弃牌堆时，你有90%的概率可以获得此牌，然后你可以弃置一名其他角色至多3张牌，并摸1~3张牌，再对其造成1点伤害。（每回合限触发3次）"..
  "<br>〖扶汉〗:锁定技，当你造成或受到伤害后，有5%的概率可以随机获得一个蜀国武将技能直到你的回合结束。若你已因此获得3个技能，则改为回复1点体力并摸两张牌（每回合限触发3次）。",
  

  ["$tshu__fuhan"] = "承先父之志，扶汉兴刘！",
  ["$tshu__fanghun"] = "暗香疏影处，凌风踏雪来！",
}

local xiaosha = General(extension, "tshujl__xiaosha","god",0,0,General.Female)
xiaosha.hidden = true
local guisha = fk.CreateTriggerSkill{
  name = "tshujl__guisha",
  anim_type = "special",
  global = true,
  priority = 11,
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("tshujl__xiaosha") > 0 and not player.dead and player.phase == Player.Play and math.random(1,10) <= 9
  end,
  on_cost = function (self,event, target, player, data)
    local n = math.random(2,4)
    if player.room:askForSkillInvoke(player,self.name,nil,"#tshujl__guisha-ask") then
      self.cost_data = n
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player,"tshujl__guisha-phase",self.cost_data)
  end,
  refresh_events = {fk.CardUsing},
  can_refresh = function(self, event, target, player, data)
    local n = player:getMark("tshujl__guisha-phase")
    return target == player and  n > 0 and data.card and  data.card.trueName == "slash" and #player.room.logic:getEventsOfScope(GameEvent.UseCard, 5, function(e)
      local use = e.data[1]
      return use.from == player.id and use.card.trueName == "slash"
    end, Player.HistoryPhase) <= 3
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local n = #player.room.logic:getEventsOfScope(GameEvent.UseCard, 5, function(e)
      local use = e.data[1]
      return use.from == player.id and use.card.trueName == "slash"
    end, Player.HistoryPhase)
    if not player.dead then
      player:drawCards(n,self.name)
    end
  end,
}
local guisha_targetmod = fk.CreateTargetModSkill{
  name = "#tshujl__guisha_targetmod",
  global = true,
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and player:getMark("tshujl__guisha-phase") > 0 then
      return player:getMark("tshujl__guisha-phase")
    end
    return 0
  end,
}
local shuli = fk.CreateTriggerSkill{
  name = "tshujl__shuli",
  anim_type = "drawcard",
  global = true,
  priority = 11,
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("tshujl__xiaosha") > 0 and not player.dead and player.phase == Player.Finish and math.random(1,20) <= 19
  end,
  on_cost = function (self,event, target, player, data)
    local n = #player.room.logic:getActualDamageEvents(9, function(e) return e.data[1].form == p end, Player.HistoryTurn)
    n = math.max(3,n)
    n = math.min(8,n)
    if player.room:askForSkillInvoke(player,self.name,nil,"#tshujl__shuli-ask") then
      self.cost_data = n
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getCardsFromPileByRule(".|.|.|.|.|basic",self.cost_data,"DiscardPile")
    if #cards > 0 then
      while true do
        room:setPlayerMark(player, "shuli_cards", cards)
        local _, ret = room:askForUseActiveSkill(player, "tshujl__shuli_active", "#shuli-give", true, nil, true)
        room:setPlayerMark(player, "shuli_cards", 0)
        if ret then
          for _, id in ipairs(ret.cards) do
            table.removeOne(cards, id)
          end
          local mark = type(player:getMark("shuli_tar-phase")) == "table" and player:getMark("shuli_tar-phase") or {}
          table.insertIfNeed(mark,ret.targets[1])
          room:setPlayerMark(player, "shuli_tar-phase", mark)
          room:moveCardTo(ret.cards, Card.PlayerHand, room:getPlayerById(ret.targets[1]), fk.ReasonGive, self.name, nil, false, player.id)
          if #cards == 0 then break end
          if player.dead then
            room:moveCards({
              ids = cards,
              toArea = Card.DiscardPile,
              moveReason = fk.ReasonJustMove,
              skillName = self.name,
            })
            break
          end
        else
          room:moveCardTo(cards, Player.Hand, player, fk.ReasonGive, self.name, nil, false, player.id)
          break
        end
      end
      room:setPlayerMark(player, "shuli_tar-phase",0)
    end
  end,
}
local shuli_active = fk.CreateActiveSkill{
  name = "tshujl__shuli_active",
  expand_pile = function(self)
    return type(Self:getMark("shuli_cards")) == "table" and Self:getMark("shuli_cards") or {}
  end,
  card_num = 1,
  target_num = 1,
  card_filter = function(self, to_select, selected, targets)
    local ids = Self:getMark("shuli_cards")
      return type(ids) == "table" and table.contains(ids, to_select)
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    local tids = type(Self:getMark("shuli_tar-phase")) == "table" and Self:getMark("shuli_tar-phase") or {}
    return #selected == 0 and to_select ~= Self.id and not table.contains(tids,to_select)
  end,
}
guisha:addRelatedSkill(guisha_targetmod)
Fk:addSkill(shuli_active)
xiaosha:addSkill(guisha)
xiaosha:addSkill(shuli)
Fk:loadTranslationTable{
  ["tshujl__xiaosha"] = "小杀",

  ["tshujl__guisha"] = "瑰杀",
  [":tshujl__guisha"] = "锁定技,出牌阶段开始时，你有90%的概率此阶段出杀次数增加2~4次，且使用前三张【杀】时摸等同于你此阶段使用【杀】次数的牌。",
  
  ["tshujl__shuli"] = "姝丽",
  [":tshujl__shuli"] = "锁定技，结束阶段，你有95%的概率从弃牌堆获得X张基本牌（X为你本回合造成的伤害数且范围为3~8），然后你可以将其中的牌交给任意名角色每人一张。",

  [":tshujl__xiaosha"] = "<br>〖瑰杀〗:锁定技,出牌阶段开始时，你有90%的概率此阶段出杀次数增加2~4次，且使用前三张【杀】时摸等同于你此阶段使用【杀】次数的牌。"..
  "<br>〖姝丽〗:锁定技，结束阶段，你有95%的概率从弃牌堆获得X张基本牌（X为你本回合造成的伤害数且范围为3~8），然后你可以将其中的牌交给任意名角色每人一张。",
  ["tshujl__shuli_active"] = "姝丽",
  ["#shuli-give"] = "姝丽：你可以将这些牌分配给任意角色各一张，点“取消”自己保留",
  ["#tshujl__guisha-ask"] = "瑰杀:是否令本阶段出【杀】次数增加2~4次,且使用前三张【杀】时摸等同出杀次数的牌。",
  ["#tshujl__shuli-ask"] = "姝丽:你可以从弃牌堆中获得3~8张基本牌，然后可以将其中的牌分配给任意名角色各一张。",

  ["$tshujl__guisha"] = "瑰姿媚丽，沙场来战。",
  ["$tshujl__shuli"] = "姿颜姝丽，决意于众。",
}

local caochun = General(extension, "tshujl__caochun","wei",0,0)
caochun.hidden = true
local shanjia = fk.CreateTriggerSkill{
  name = "tshu__shanjia",
  anim_type = "drawcard",
  global = true,
  priority = 11,
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return  player:getMark("tshujl__caochun") > 0  and not player.dead and math.random(1,20) <= 17 and target.phase == Player.Play and  player:usedSkillTimes(self.name, Player.HistoryRound) < 3
  end,
  on_cost = function (self,event, target, player, data)
    if target ~= player then
      return player.room:askForSkillInvoke(player,self.name,nil,"缮甲：你可以摸2~4张牌。")
    else
      return player.room:askForSkillInvoke(player,self.name,nil,"缮甲：你可以摸2~4张牌，然后可以视为使用一张无法被响应且伤害+1~2点的【杀】。")
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(math.random(2,4),self.name)
    if not player.dead and target == player then
      local use = U.askForUseVirtualCard(room, player, "slash", nil, self.name,"缮甲：你可以视为使用一张无法被响应且伤害+1~2点的【杀】。",true,true,true,true,nil,true)
      if use then
        use.additionalDamage = (use.additionalDamage or 0) + math.random(1,2)
        use.disresponsiveList = table.map(player.room.alive_players, Util.IdMapper)
        room:useCard(use)
      end
    end
  end,
}
local xiaorui = fk.CreateTriggerSkill{
  name = "tshu__xiaorui",
  anim_type = "offensive",
  global = true,
  priority = 11,
  frequency = Skill.Compulsory,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("tshujl__caochun") > 0  and not player.dead and math.random(1,100) <= 95 and data.to and data.to ~= player and  player:usedSkillTimes(self.name, Player.HistoryTurn) < 4
  end,
  on_cost = function (self,event, target, player, data)
    return player.room:askForSkillInvoke(player,self.name,nil,"骁锐：你可以随机获得 %dest 的1~4张牌并令对其的伤害+1~4。::"..data.to.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if not data.to:isNude() then
      local cards = data.to:getCardIds("he")
      room:moveCardTo(table.random(cards,math.random(1,4)),Card.PlayerHand,player,fk.ReasonPrey,self.name)
    end
    data.damage = data.damage + math.random(1,4)
  end,
}
caochun:addSkill(shanjia)
caochun:addSkill(xiaorui)
Fk:loadTranslationTable{
  ["tshujl__caochun"] = "曹纯",

  ["tshu__shanjia"] = "缮甲",
  [":tshu__shanjia"] = "锁定技,每名角色的出牌阶段开始时，你有85%的概率可以摸2~4张牌，然后若此时是你的回合内，你可以视为使用一张【杀】，此【杀】不能被响应且伤害+1~2。（每轮限3次）",
  
  ["tshu__xiaorui"] = "骁锐",
  [":tshu__xiaorui"] = "锁定技，当你对其他角色造成伤害时，你有90%的概率随机获得其1~4张牌且此伤害+1~4（每回合限触发4次）。",

  [":tshujl__caochun"] = "<br>〖缮甲〗:锁定技,每名角色的出牌阶段开始时，你有85%的概率可以摸2~4张牌，然后若此时是你的回合内，你可以视为使用一张【杀】，此【杀】不能被响应且伤害+1~2。（每轮限3次）"..
  "<br>〖骁锐〗:锁定技，当你对其他角色造成伤害时，你有90%的概率随机获得其1~4张牌且此伤害+1~4（每回合限触发4次）。",


  ["$tshu__shanjia"] = "纲纪督御，不失其理。",
  ["$tshu__xiaorui"] = "兵法之道，有武且要晓人心。",
}


local guanyu = General(extension, "tshujl__guanyu","god",0,0)
guanyu.hidden = true
local wushen = fk.CreateTriggerSkill{
  name = "tshu__wushen",
  anim_type = "offensive",
  global = true,
  priority = 11,
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return  target == player and player:getMark("tshujl__guanyu") > 0  and not player.dead and math.random(1,20) <= 17 and target.phase == Player.Start 
  end,
  on_cost = function (self,event, target, player, data)
      local targets =  player.room:askForChoosePlayers(player,table.map(player.room:getOtherPlayers(player), Util.IdMapper),1,3,"武神：你可以对至多三名角色各使用一张【杀】，此【杀】结算时若造成了伤害，你摸一张牌。")
      if #targets > 0 then
        self.cost_data = targets
        return true
      end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, pid in ipairs(self.cost_data) do
      local p = room:getPlayerById(pid)
      if p.dead or player.dead then break end
      room:useVirtualCard("slash", nil, player, {p}, self.name)
    end
  end,
  refresh_events = {fk.CardUseFinished},
  can_refresh = function(self, event, target, player, data)
    return target == player and data.card and data.card.name == "slash" and data.damageDealt and table.contains(data.card.skillNames,self.name) and not player.dead
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(1,self.name)
  end,
}
local wuhun = fk.CreateTriggerSkill{
  name = "tshu__wuhun",
  global = true,
  priority = 11,
  anim_type = "control",
  events = {fk.Damaged,fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if event == fk.Damaged then
      return player:getMark("tshujl__guanyu") > 0 and not target.dead and (target == player or player:distanceTo(target) <= 1 ) and not target:isRemoved()
      and player.phase == Player.NotActive and math.random(1,10) <= 8
    elseif  event == fk.TurnEnd then
      return player:getMark("tshujl__guanyu") > 0 and player:getMark("tshu__wuhun-turn") > 0 and player:getMark("@tshu__wuhun") > 0 and not target.dead
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.Damaged then return true end
    if player:getMark("@tshu__wuhun") > 0 then
      local n = player:getMark("@tshu__wuhun")
      return player.room:askForSkillInvoke(player, self.name, nil, "武魂：你可以令 %dest 失去 %arg 点体力。::"..target.id..":"..n)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damaged then
      if player:getMark("@tshu__wuhun") < 5 then
        room:addPlayerMark(player,"@tshu__wuhun",1)
      end
      room:setPlayerMark(player,"tshu__wuhun-turn",1)
    elseif event == fk.TurnEnd then
      local n = player:getMark("@tshu__wuhun")
      room:loseHp(target,n,self.name)
    end
  end,
}
guanyu:addSkill(wuhun)
guanyu:addSkill(wushen)
Fk:loadTranslationTable{
  ["tshujl__guanyu"] = "神关羽",

  ["tshu__wushen"] = "武神",
  [":tshu__wushen"] = "锁定技,准备阶段，你有85%的概率视为对至多3名角色各使用一张【杀】。此【杀】结算时若造成了伤害,则你摸一张牌。",
  
  ["tshu__wuhun"] = "武魂",
  [":tshu__wuhun"] = "锁定技，你的回合外，与你距离1以内的角色受到伤害后，你有80%的概率获得1个“梦魇”标记。此回合结束时，若你有梦魇标记，你可令当前回合角色失去X点体力（X为“梦魇”标记数量且最多为5）。",

  [":tshujl__guanyu"] = "<br>〖武神〗:锁定技,准备阶段，你有85%的概率视为对至多3名角色各使用一张【杀】。此【杀】结算时若造成了伤害,则你摸一张牌。"..
  "<br>〖武魂〗:锁定技，你的回合外，与你距离1以内的角色受到伤害后，你有80%的概率获得1个“梦魇”标记。此回合结束时，若你有梦魇标记，你可令当前回合角色失去X点体力（X为“梦魇”标记数量且最多为5）",

  ["@tshu__wuhun"] = "梦魇",
  ["$tshu__wuhun"] = "不杀此人，何以雪恨！",
}



local zhaoyun = General(extension, "tshujl__zhaoyun","god",0,0)
zhaoyun.hidden = true
local juejing = fk.CreateTriggerSkill{
  name = "tshu__juejing",
  anim_type = "support",
  global = true,
  priority = 11,
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart,fk.EnterDying,fk.AfterDying},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("tshujl__zhaoyun") > 0 and not player.dead  and ((event == fk.EventPhaseStart and (player.phase == Player.Start or player.phase == Player.Finish)) or (event == fk.EnterDying or (event == fk.AfterDying and player.hp > 0) )) 
    and math.random(1,10) <= 9 and player:usedSkillTimes(self.name, Player.HistoryTurn) < 3
  end,
  on_cost = function (self,event, target, player, data)
    return player.room:askForSkillInvoke(player,self.name,nil,"绝境：你可以摸2~4张牌并回复1点体力。")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if not player.dead then
      player:drawCards(math.random(2,4),self.name)
    end
    if not player.dead and player:isWounded() then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    end
  end,
}
local longhun = fk.CreateTriggerSkill{
  name = "tshu__longhun",
  anim_type = "special",
  global = true,
  priority = 11,
  frequency = Skill.Compulsory,
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("tshujl__zhaoyun") > 0 and not player.dead and (data.card.name == "peach" or data.card.trueName == "slash" or ((data.card.name == "jink" or data.card.name == "nullification") and not player.room.current:isNude())) and math.random(1,10) <= 9
  end,
  on_cost = function(self, event, target, player, data)
    if data.card.name == "jink" or data.card.name == "nullification" then
      return player.room:askForSkillInvoke(player,self.name,nil,"龙魂：你可以获得%dest至多两张牌。::"..player.room.current.id)
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
      if data.card.name == "peach"  then
        data.additionalRecover = (data.additionalRecover or 0) + math.random(1,3)
      elseif data.card.trueName == "slash"  then
        data.additionalDamage = (data.additionalDamage or 0) + math.random(1,3)
      else
        local cards = room:askForCardsChosen(player,room.current,1,2, "he", self.name)
        if #cards > 0 then
          room:obtainCard(player, cards, false, fk.ReasonPrey)
        end
      end
  end,
}
zhaoyun:addSkill(juejing)
zhaoyun:addSkill(longhun)
Fk:loadTranslationTable{
  ["tshujl__zhaoyun"] = "神赵云",

  ["tshu__juejing"] = "绝境",
  [":tshu__juejing"] = "锁定技，准备阶段、结束阶段或当你进入或脱离濒死状态时，你有90%的概率摸二至四张牌并回复1点体力（每回合限三次）。",
  
  ["tshu__longhun"] = "龙魂",
  [":tshu__longhun"] = "锁定技，你使用【杀】或【桃】时，有90%的概率此牌伤害或回复值+1~3，且你使用【闪】或【无懈可击】时，有90%概率可以获得当前回合角色至多两张牌。",

  [":tshujl__zhaoyun"] = "<br>〖绝境〗:锁定技，准备阶段、结束阶段或当你进入或脱离濒死状态时，你有90%的概率摸二至四张牌并回复1点体力（每回合限三次）。"..
  "<br>〖龙魂〗:锁定技，你使用【杀】或【桃】时，有90%的概率此牌伤害或回复值+1~3，且你使用【闪】或【无懈可击】时，有90%概率可以获得当前回合角色至多两张牌。",

  ["$tshu__juejing"] = "置之死地，方能后生！",
  ["$tshu__longhun"] = "常山赵子龙在此！",
}

local zhouyi = General(extension, "tshujl__zhouyi","wu",0,0,General.Female)
zhouyi.hidden = true
local zhukou = fk.CreateTriggerSkill{
  name = "tshu__zhukou",
  anim_type = "drawcard",
  global = true,
  priority = 11,
  frequency = Skill.Compulsory,
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
      local room = player.room
      if event == fk.Damage then
        if target == player and player:getMark("tshujl__zhouyi") > 0 and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and math.random(1,10) <= 9 then
        if room.current and room.current.phase == Player.Play then
          local n = 0
          player.room.logic:getEventsOfScope(GameEvent.UseCard, 999, function(e)
            local use = e.data[1]
            if use.from == player.id  then
              n = n + 1
            end
          end, Player.HistoryTurn)
          self.cost_data = n
          return n > 0
        end
        end
      end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local x = self.cost_data
      return room:askForSkillInvoke(player, self.name,nil,"逐寇：你可以摸"..x.."张牌并回复1点体力。")
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.Damage then
      local x = self.cost_data
      if x > 0 then
        player:drawCards(x, self.name)
      end
      if player:isWounded() then
        player.room:recover({
          who = player,
          num = 1,
          recoverBy = player,
          skillName = self.name
        })
      end
    end
  end,
}
local mengqing = fk.CreateTriggerSkill{
  name = "tshu__mengqing",
  anim_type = "offensive",
  global = true,
  priority = 11,
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("tshujl__zhouyi") > 0 and not player.dead  and player.phase == Player.Start 
    and math.random(1,20) <= 17
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {"tshu__yuyun1", "tshu__yuyun2", "tshu__yuyun3", "tshu__yuyun4", "Cancel"}
    local n = 1
    for _, p in ipairs(room.alive_players) do
      if p:isWounded() then
        n = n + 1
      end
    end
    n = math.min(4,n)
    for i = 1, n, 1 do
      if player.dead then break end
      local choice = room:askForChoice(player,choices,self.name,"氓情：还可选择"..(n-i).."项",false,{"tshu__yuyun1", "tshu__yuyun2", "tshu__yuyun3", "tshu__yuyun4", "Cancel"})
      if choice == "Cancel" then
        break
      else
        table.removeOne(choices,choice)
        if choice == "tshu__yuyun1" then
          local targets = {}
          for _, p in ipairs(room.alive_players) do
            table.insert(targets,p.id)
          end
          local tar = room:askForChoosePlayers(player,targets,1,1,"氓情：选择一名角色对其造成2点伤害。",self.name,true)
          if #tar > 0 then
            room:damage({
              from = player,
              to = room:getPlayerById(tar[1]),
              damage = 2,
              damageType = fk.NormalDamage,
              skillName = self.name,
            })
          end
        elseif choice == "tshu__yuyun2" then
          player:drawCards(math.random(2,3),self.name)
        elseif choice == "tshu__yuyun3" then
          room:setPlayerMark(player,"tshu__mengqing_slash-turn",1)
        elseif choice == "tshu__yuyun4" then
          room:addPlayerMark(player, MarkEnum.AddMaxCardsInTurn,3)
        end
      end
    end
  end,
}
local mengqing_targetmod = fk.CreateTargetModSkill{
  name = "#tshujl__mengqing_targetmod",
  global = true,
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and player:getMark("tshu__mengqing_slash-turn") > 0 then
      return 3
    end
    return 0
  end,
}
mengqing:addRelatedSkill(mengqing_targetmod)
zhouyi:addSkill(zhukou)
zhouyi:addSkill(mengqing)
Fk:loadTranslationTable{
  ["tshujl__zhouyi"] = "周夷",

  ["tshu__zhukou"] = "逐寇",
  [":tshu__zhukou"] = "锁定技，当你于一名角色的出牌阶段造成伤害后，你有90%的概率摸等同于你本回合已使用牌数张牌并回复1点体力（每回合限触发一次）。",
  ["tshu__yuyun1"] = "对一名角色造成2点伤害",
  ["tshu__yuyun2"] = "摸2~3张牌",
  ["tshu__yuyun3"] = "本回合出牌阶段多使用3张【杀】",
  ["tshu__yuyun4"] = "本回合手牌上限+3",

  
  ["tshu__mengqing"] = "氓情",
  [":tshu__mengqing"] = "锁定技，准备阶段，你有85%的概率选择一项（发动技能时每有一个受伤角色便可多选一项）：1.对一名角色造成2点伤害；2.摸2~3张牌；3.本回合出牌阶段可以多使用3张【杀】；4.本回合手牌上限+4。",

  [":tshujl__zhouyi"] = "<br>〖逐寇〗:锁定技，每回合限一次，当你于一名角色的出牌阶段造成伤害后，你有90%的概率摸X张牌并回复1点体力（X为本回合你已使用的牌数）。"..
  "<br>〖氓情〗:锁定技，准备阶段，你有85%的概率选择一项（发动技能时每有一个受伤角色可多选一项）：1.对一名角色造成2点伤害；2.摸2~3张牌；3.本回合出牌阶段可以多使用3张【杀】；4.本回合手牌上限+4。",

  ["$tshu__zhukou"] = "轻装上阵，利剑出鞘。",
  ["$tshu__mengqing"] = "女之耽兮，不可说也。",
}




local nianzhuge = General(extension, "tshujl__nianzhugeliang","shu",0,0)
nianzhuge.hidden = true
local xinghan = fk.CreateTriggerSkill{
  name = "tshu__xinghan",
  anim_type = "control",
  global = true,
  priority = 11,
  frequency = Skill.Compulsory,
  events = {fk.TurnStart,fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("tshujl__nianzhugeliang") > 0 and player:usedSkillTimes(self.name, Player.HistoryTurn) < 2 and math.random(1,10) <= 8
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name,nil,"定乱：你可以增加一点体力上限并回复一点体力，然后随机变更一名角色势力并摸2~4张牌。")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player,1)
    if player:isWounded() and not player.dead then
        room:recover{
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
        }
    end
    if not player.dead then
      player:drawCards(math.random(2,4),self.name)
    end
    local ps = {}
    for _, p in ipairs(room.alive_players) do
      if p.kingdom ~= "shu" then
        table.insert(ps,p)
      end
    end
    if #ps > 0 then
      room:changeKingdom(table.random(ps), "shu", true)
    end
  end,
}
local liaoyuan = fk.CreateTriggerSkill{
  name = "tshu__liaoyuan",
  anim_type = "offensive",
  global = true,
  mute = true,
  priority = 11,
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart,fk.CardUsing,fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    if player.dead then return end
    if event == fk.EventPhaseStart then
      return target == player and player:getMark("tshujl__nianzhugeliang") > 0 and  not player:prohibitUse(Fk:cloneCard("fire_attack")) and player.phase == Player.Play and math.random(1,20) <= 17
    elseif event == fk.CardUsing then
      return target == player and player:getMark("tshujl__nianzhugeliang") > 0 and data.card.name == "fire_attack" and math.random(1,20) <= 17 
    elseif event == fk.DamageCaused then
      return target == player and player:getMark("tshujl__nianzhugeliang") > 0 and data.card and data.card.name == "fire_attack" and not data.chain and math.random(1,20) <= 17  and player:getMark("tshu__liaoyuan-phase") < 6 
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      if player.id < 0 then
        return true
      end
      return player.room:askForSkillInvoke(player, self.name,nil,"燎原：你可以视为使用一张【火攻】。")
    elseif event == fk.CardUsing then
      local targets = player.room:getUseExtraTargets( data)
      local n = #targets
      if n == 0 then return false end
      
      if player.id < 0 then
        local enemy_targets = {}
        for _, id in ipairs(targets) do
          local p = room:getPlayerById(id)
          if p and p.role ~= player.role then
            table.insert(enemy_targets, id)
          end
        end
        if #enemy_targets > 0 then
          self.cost_data = enemy_targets
          return true
        end
      end
      
      local tos = room:askForChoosePlayers(player, targets, 1, n, "#tshu__liaoyuan-choose:::"..data.card:toLogString(), self.name, true)
      if #tos > 0 then
        self.cost_data = tos
        return true
      end
    elseif event == fk.DamageCaused then
      local n = 0
      for _, p in ipairs(room.alive_players) do
        if p.kingdom == "shu" then
          n = n + 1
        end
      end
      n = math.max(1,n)
      self.cost_data = n
      
      if player.id < 0 then
        return true
      end
      
      return player.room:askForSkillInvoke(player, self.name,nil,"燎原：是否令对"..Fk:translate(data.to.general).."的伤害+"..n.."？")
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      player:broadcastSkillInvoke(self.name)
      room:notifySkillInvoked(player,self.name,"offensive")
      
      if player.id < 0 then
        room:addPlayerMark(player,"tshu__liaoyuan-phase",1)
        local cards = room:getCardsFromPileByRule(".|.|.|.|.|trick",math.random(1,3),"allPiles")
        if #cards > 0 then
          room:moveCards({
            ids = cards,
            to = player.id,
            toArea = Card.PlayerHand,
            moveReason = fk.ReasonJustMove,
            proposer = player.id,
            skillName = self.name,
          })
        end
      end
      
      U.askForUseVirtualCard(room, player, "fire_attack", nil, self.name)
    elseif event == fk.CardUsing then
      table.forEach(self.cost_data, function (id)
        table.insert(data.tos, {id})
      end)
      
      if player.id > 0 then
        room:notifySkillInvoked(player,self.name,"drawCards")
        room:addPlayerMark(player,"tshu__liaoyuan-phase",1)
        local cards = room:getCardsFromPileByRule(".|.|.|.|.|trick",math.random(1,3),"allPiles")
        if #cards > 0 then
          room:moveCards({
            ids = cards,
            to = player.id,
            toArea = Card.PlayerHand,
            moveReason = fk.ReasonJustMove,
            proposer = player.id,
            skillName = self.name,
          })
        end
      end
    elseif event == fk.DamageCaused then
      player:broadcastSkillInvoke(self.name)
      data.damage = data.damage + self.cost_data
    end
  end,
}
local liaoyuan_targetmod = fk.CreateTargetModSkill{
  name = "#tshujl__liaoyuan_targetmod",
  global = true,
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and player:getMark("tshu__liaoyuan-phase") > 0 then
      return player:getMark("tshu__liaoyuan-phase")
    end
    return 0
  end,
}
liaoyuan:addRelatedSkill(liaoyuan_targetmod)
nianzhuge:addSkill(xinghan)
nianzhuge:addSkill(liaoyuan)
Fk:loadTranslationTable{
  ["tshujl__nianzhugeliang"] = "念·诸葛亮",
  ["tshujl__nianzhuge_choice"] = "诸葛亮",

  ["tshu__xinghan"] = "定乱",
  [":tshu__xinghan"] = "锁定技，回合开始时或当你受到伤害后，你有80%概率增加一点体力上限并回复一点体力，然后摸2~4张牌并随机将场上一名非\"蜀\"势力角色变更为\"蜀\"势力（每回合限触发两次）。",

  
  ["tshu__liaoyuan"] = "燎原",
  [":tshu__liaoyuan"] = "锁定技，出牌阶段开始时你有85%的概率可以视为使用一张【火攻】，且你使用【火攻】时85%概率可以额外指定任意名角色成为目标；<br>每当你使用【火攻】造成伤害时，有85%概率令此伤害增加等同场上\"蜀\"势力角色数(至少为1），然后你本阶段出【杀】次数+1并从牌堆或弃牌堆随机获得1~3张锦囊牌（此项每阶段限触发6次）。",

  ["#tshu__liaoyuan-choose"] = "燎原：你可以多选择任意名角色成为 %arg 的目标。",
  [":tshujl__nianzhugeliang"] = "<br>〖定乱〗:锁定技，回合开始时或当你受到伤害后，你有80%概率增加一点体力上限并回复一点体力，然后摸2~4张牌并随机将场上一名非\"蜀\"势力角色变更为\"蜀\"势力（每回合限触发两次）。"..
  "<br>〖燎原〗:锁定技，出牌阶段开始时你有85%的概率可以视为使用一张【火攻】，且你使用【火攻】时85%概率可以额外指定任意名角色成为目标；<br>每当你使用【火攻】造成伤害时，有85%概率令此伤害增加等同场上\"蜀\"势力角色数(至少为1），然后你本阶段出【杀】次数+1并从牌堆或弃牌堆随机获得1~3张锦囊牌（此项每阶段限触发6次）。",

  ["$tshu__xinghan"] = "料事如神，随机应变。",
  ["$tshu__liaoyuan"] = "黄龙翔天，离火灭世！",
}


local miaolvlingqi = General(extension, "tshujl__miaolvlingqi","qun",0,0)
miaolvlingqi.hidden = true
local guowu = fk.CreateTriggerSkill{
  name = "tshujl__guowu",
  anim_type = "offensive",
  global = true,
  mute = true,
  priority = 11,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("tshujl__miaolvlingqi") ~= 0 and not player.dead and player.phase == Player.Play 
  end,
  on_cost = function (self, event, target, player, data)
    if player.id < 0 then
      return true
    end
    return player.room:askForSkillInvoke(player,self.name,nil,"帼武：是否获得技能〖无双〗并令你本阶段使用牌无距离次数限制，且可多指定两名目标或令使用的牌额外结算一次。")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player,self.name)
    player:broadcastSkillInvoke(self.name,math.random(1,2))
    if not player:hasSkill("wushuang",true) then
      room:addPlayerMark(player,"tshujl__miaolvlingqi-turn", 1)
      room:handleAddLoseSkills(player,"wushuang")
    end
    room:addPlayerMark(player,"tshujl__miaolvlingqi-phase", 1)
  end,
  refresh_events = {fk.TurnEnd},
  can_refresh = function (self, event, target, player, data)
    return player:getMark("tshujl__miaolvlingqi-turn") > 0 
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:handleAddLoseSkills(player,"-wushuang")
  end,
}
local guowu_delay = fk.CreateTriggerSkill{
  name = "#tshujl__guowu_delay",
  anim_type = "offensive",
  global = true,
  priority = 11,
  frequency = Skill.Compulsory,
  events = {fk.CardUseFinished,fk.AfterCardTargetDeclared},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if player:getMark("tshujl__miaolvlingqi") == 0 or player:getMark("tshujl__miaolvlingqi-phase") == 0 or player.dead then return end
    if event == fk.CardUseFinished then
      if target == player and player:getMark("tshujl__miaolvlingqi-phase") > 0 and not player.dead and
        (data.card:isCommonTrick() or table.contains({"slash","peach","analeptic"},data.card.trueName)) then
          return not table.contains(data.card.skillNames,self.name)
      end
    elseif event == fk.AfterCardTargetDeclared then
      return target == player and player:getMark("tshujl__miaolvlingqi-phase") > 0 and not player.dead and
      (data.card:isCommonTrick() or data.card.trueName == "slash") and #player.room:getUseExtraTargets( data) > 0
    end
  end,
  on_cost = function (self, event, target, player, data)
    if event == fk.CardUseFinished then
      if player.id < 0 then
        return true
      end
      return player.room:askForSkillInvoke(player,self.name,nil,"帼武：是否令【"..Fk:translate(data.card.name).."】额外执行一次效果？")
    elseif event == fk.AfterCardTargetDeclared then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUseFinished then
      room:notifySkillInvoked(player,self.name)
      player:broadcastSkillInvoke(guowu.name,math.random(5,6))
      local name = Fk:cloneCard(data.card.name)
      name.skillName = self.name
      local use ={
      from = player.id,
      tos = data.tos,
      card = name,
      extraUse = true
      }
      room:useCard(use)
    elseif event == fk.AfterCardTargetDeclared then
      local targets = player.room:getUseExtraTargets( data)
      if #targets == 0 then return false end
      local tos = room:askForChoosePlayers(player, targets, 1, 2, "#tshujl__guowu-choose:::"..data.card:toLogString(), guowu.name, true)
      player:broadcastSkillInvoke(guowu.name,math.random(3,4))
      if #tos > 0 then
      table.forEach(tos, function (id)
        table.insert(data.tos, {id})
      end)
      end
    end
  end,
}
local guowu_targetmod = fk.CreateTargetModSkill{
  name = "#tshujl__guowu_targetmod",
  global = true,
  priority = 11,
  bypass_times =  function(self, player)
    return player:getMark("tshujl__miaolvlingqi-phase") > 0
  end,
  bypass_distances =  function(self, player)
    return player:getMark("tshujl__miaolvlingqi-phase") > 0
  end,
}

local zhuangrong = fk.CreateTriggerSkill{
  name = "tshujl__zhuangrong",
  anim_type = "drawcard",
  priority = 11,
  frequency = Skill.Compulsory,
  events = {fk.HpChanged,fk.AfterCardsMove},
  global = true,
  can_trigger = function(self, event, target, player, data)
    if player:getMark("tshujl__miaolvlingqi") == 0 or player:usedSkillTimes(self.name, Player.HistoryTurn) ~= 0 or player.dead or ((event == fk.HpChanged and player.hp > 1 )or(event == fk.AfterCardsMove and player:getHandcardNum() > 1)) then return end
    if event == fk.HpChanged then
      return target == player and  player.hp <= 1
    elseif event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand then
              return player:getHandcardNum() <= 1
            end
          end
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    if player.id < 0 then
      return true
    end
    return player.room:askForSkillInvoke(player,self.name,nil,"妆戎：是否将体力值和手牌数补至体力上限？(手牌至多补至100张)")
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local n = math.min(100,player.maxHp) - player:getHandcardNum()
    if n > 0 then
      player:drawCards(n,self.name)
    end
    local m = player.maxHp - player.hp
    if m > 0 and not player.dead then
      player.room:recover{
        who = player,
        num = m,
        recoverBy = player,
        skillName = self.name
      }
    end
  end,
}
guowu:addRelatedSkill(guowu_delay)
guowu:addRelatedSkill(guowu_targetmod)
miaolvlingqi:addSkill(guowu)
miaolvlingqi:addSkill(zhuangrong)
Fk:loadTranslationTable{
  ["tshujl__miaolvlingqi"] = "喵·吕玲绮",
  ["tshujl__miaolvlingqi_choice"] = "吕玲绮",
  ["#tshujl__guowu-choose"] = "帼武：你可以为%arg增加至多两个目标",
  ["tshujl__guowu"] = "帼武",
  ["#tshujl__guowu_delay"] = "帼武",
  ["#tshujl__guowu_targetmod"] = "帼武",
  [":tshujl__guowu"] = "锁定技，你的出牌阶段开始时，你本回合可以获得技能〖无双〗，然后令你此阶段使用牌时：无距离次数限制，使用【桃】、【酒】、【杀】或普通锦囊牌时可额外指定两个目标且可令此牌额外结算一次。",
  ["tshujl__zhuangrong"] = "妆戎",
  [":tshujl__zhuangrong"] = "锁定技，当你的体力值或手牌张数降至1点及以下时，你可以将体力值和手牌数补至体力上限(每回合限触发一次）。",
  [":tshujl__miaolvlingqi"] = "<br>〖帼武〗:锁定技，你的出牌阶段开始时，你本回合可以获得技能〖无双〗，然后令你于此阶段使用牌时：无距离次数限制，使用【桃】、【酒】、【杀】或普通锦囊牌时可额外指定两个目标且可令此牌额外结算一次。"..
  "<br>〖妆戎〗:锁定技，当你的体力值或手牌张数降至1点及以下时，你可以将体力值和手牌数补至体力上限(每回合限触发一次）。",

  ["$tshujl__guowu1"] = "吕家女儿胜须眉，胭脂红妆配武裳！",
  ["$tshujl__guowu2"] = "古识父子今识我，红袖弄钺话铿锵！",
  ["$tshujl__guowu3"] = "策烈马以啸西风，率锐士而擒敌酋。",
  ["$tshujl__guowu4"] = "握长兵以斩白日，横画戟而断流星。",
  ["$tshujl__guowu5"] = "被兕甲，跨良骥，挥画戟，踏兖冀。",
  ["$tshujl__guowu6"] = "束长缨，率骠骑，奔千里，破万兵。",
  ["$tshujl__zhuangrong1"] = "吕家有女初长成，戟出名扬天下惊！",
  ["$tshujl__zhuangrong2"] = "试问天下武夫，谁配画戟方天！",
}

local doupo = fk.CreateTriggerSkill{
  name = "tshujl__doupo",
  anim_type = "offensive",
  priority = 11,
  frequency = Skill.Compulsory,
  events = {fk.TurnStart,fk.Damaged},
  global = true,
  can_trigger = function(self, event, target, player, data)
    if target ~= player or player:getMark("tshujl__nianlvbu") == 0 or player:usedSkillTimes(self.name, Player.HistoryTurn) ~= 0 or player.dead then return end
    return not player:isKongcheng()
  end,
  on_cost = function (self, event, target, player, data)
    local tars = {}
    for _, p in ipairs(player.room:getOtherPlayers(player)) do
      if not player:isProhibited(p,Fk:cloneCard "duel") then
        table.insertIfNeed(tars,p.id)
      end
    end
    if #tars > 0 then
      local tar = player.room:askForChoosePlayers(player,tars,1,#tars,"斗破：你可以选择任意名其他角色成为目标，然后你可将手牌依次当做无法响应且基础伤害增加的【决斗】对其使用。")
      if #tar > 0 then
        self.cost_data = tar
        return true
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local mark = type(player:getMark("@[tshu__tianshu]")) == "table" and player:getMark("@[tshu__tianshu]") or {}
    local skills = {}
    for _, s in ipairs(player.player_skills) do
      if not (s.attached_equip or s.name[#s.name] == "&" or string.sub(s.name, 1,1) == "#") and not table.contains(mark,s.name) then
        table.insert(skills,s.name)
      end
    end
    if #skills < 1 or player.dead then return end
    local gskills = T2.choosemarkskillask(player,skills,room,0,1,"移除技能加伤")
    local n = 0
    if  gskills and #gskills >= 1 then 
      player:broadcastSkillInvoke(self.name)
      room:handleAddLoseSkills(player, "-"..table.concat(gskills, "|-"), nil)
      n = n + #gskills
    end
    room:setPlayerMark(player,self.name.."-phase",n)
    for i = 1, 999, 1 do
      if player.dead or player:isKongcheng() then break end
      local tars = {}
      for _, pid in ipairs(self.cost_data) do
        local p = room:getPlayerById(pid)
        if not p.dead and not player:isProhibited(p,Fk:cloneCard "duel")  then
          table.insertIfNeed(tars,pid)
        end
      end
      if #tars <= 0 then break end
      local card = room:askForCard(player,1,1,false,self.name,true,".","斗破：选择一张手牌，然后将其作为【决斗】对你选择的目标使用。")
      if #card <= 0 then break end
      local duel = Fk:cloneCard "duel"
      duel.skillName = self.name
      duel.disresponsive = true
      duel.additionalDamage = (duel.additionalDamage or 0) + n
      card = Fk:getCardById(card[1])
      duel:addSubcard(card)
      local tar = {}
      for _, pid in ipairs(self.cost_data) do
        local p = room:getPlayerById(pid)
        if not p.dead and not player:isProhibited(p,Fk:cloneCard "duel") and player:canUseTo(duel, p) then
          table.insertIfNeed(tar,p)
        end
      end
      if #tar > 0 then
        room:useVirtualCard("duel", {card}, player,tar, self.name, true)
      else
        break
      end
    end
    room:setPlayerMark(player,self.name.."-phase",0)
  end,
  refresh_events = {fk.CardUsing},
  can_refresh = function (self, event, target, player, data)
    return target and target == player and data.card.name == "duel" and table.contains(data.card.skillNames,self.name)
  end,
  on_refresh = function (self, event, target, player, data)
    local n = player:getMark(self.name.."-phase") or 0
    data.disresponsiveList = table.map(player.room.players,Util.IdMapper)
    data.additionalDamage = (data.additionalDamage or 0) + n
  end,
}
local tazheng = fk.CreateTriggerSkill{
  name = "tshujl__tazheng",
  anim_type = "offensive",
  priority = 11,
  frequency = Skill.Compulsory,
  events = {fk.Damage},
  global = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("tshujl__nianlvbu") > 0 and  player:usedSkillTimes(self.name, Player.HistoryTurn) < 2 and not player.dead and data.to and data.to ~= player and not data.to.dead
  end,
  on_cost = function (self, event, target, player, data)
    local n = data.damage
    return player.room:askForSkillInvoke(player,self.name,nil,"踏阵：你可以令 "..Fk:translate(data.to.general).." 直到你的下回合开始前无法对你使用牌，并可偷取其至多 "..n.." 个技能。")
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local mark = type(player:getMark(self.name)) == "table" and player:getMark(self.name) or {}
    table.insertIfNeed(mark,data.to.id)
    room:setPlayerMark(player,self.name,mark)
    local mark2 = type(data.to:getMark("@@"..self.name)) == "table" and data.to:getMark("@@"..self.name) or {}
    table.insertIfNeed(mark2,player.id)
    room:setPlayerMark(data.to,"@@"..self.name,mark2)
    local skills = {}
    for _, s in ipairs(data.to.player_skills) do
      if not (s.attached_equip or s.name[#s.name] == "&" or string.sub(s.name, 1,1) == "#") then
        table.insertIfNeed(skills,s.name)
      end
    end
    if #skills <= 0 then return end
    local gskills = T2.choosemarkskillask(player,skills,room,0,data.damage,"选择 "..Fk:translate(data.to.general).." 至多"..data.damage.."个技能偷取之")
    if  gskills and #gskills >= 1 then 
      room:handleAddLoseSkills(data.to, "-"..table.concat(gskills, "|-"), nil)
      room:handleAddLoseSkills(player,table.concat(gskills, "|"), nil)
    end
  end,
  refresh_events = {fk.TurnStart,fk.BuryVictim},
  can_refresh = function (self, event, target, player, data)
    return target == player and (type(player:getMark(self.name)) == "table" and #player:getMark(self.name) > 0)
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local mark = type(player:getMark(self.name)) == "table" and player:getMark(self.name) or {}
    if #mark > 0 then
      room:setPlayerMark(player,self.name,0)
      for _, pid in ipairs(mark) do
        local p = room:getPlayerById(pid)
        local mark2 = type(p:getMark("@@"..self.name)) == "table" and p:getMark("@@"..self.name) or {}
        table.removeOne(mark2,player.id)
        if #mark2 > 0 then
          room:setPlayerMark(p,"@@"..self.name,mark2)
        else
          room:setPlayerMark(p,"@@"..self.name,0)
        end
      end
    end
  end,
}
local tazheng_buff = fk.CreateProhibitSkill{
  name = "#tshujl_tazheng_buff",
  frequency = Skill.Compulsory,
  global = true,
  is_prohibited = function(self, from, to, card)
    local m = type(to:getMark(tazheng.name)) == "table" and to:getMark(tazheng.name) or {}
    if table.contains(m,from.id) then
      return true
    end
  end,
}
tazheng:addRelatedSkill(tazheng_buff)
local nianlvbu = General(extension, "tshujl__nianlvbu","qun",0,0)
nianlvbu.hidden = true
nianlvbu:addSkill(doupo)
nianlvbu:addSkill(tazheng)
Fk:loadTranslationTable{
  ["tshujl__nianlvbu"] = "念·吕布",
  ["tshujl__nianlvbu_choice"] = "吕布",

  ["tshujl__doupo"] = "斗破",
  [":tshujl__doupo"] = "锁定技，你的回合开始时或当你受到伤害后，你可以选择任意个目标并移除任意个技能，然后可以依次将手牌作为不可响应且基础伤害增加移除技能数的【决斗】对目标使用(每回合限触发一次)。",
  ["tshujl__tazheng"] = "踏阵",
  ["@@tshujl__tazheng"] = "踏阵",
  ["#tshujl_tazheng_buff"] = "踏阵",
  [":tshujl__tazheng"] = "锁定技，当你造成伤害后，你可以令目标直到你的下回合开始前无法对你使用牌，然后你可偷取目标至多等同此次伤害量个技能(每回合限触发两次）。",
  [":tshujl__nianlvbu"] = "<br>〖斗破〗:锁定技，你的回合开始时或当你受到伤害后，你可以选择任意个目标并移除任意个技能，然后可以依次将手牌作为不可响应且基础伤害增加移除技能数的【决斗】对目标使用(每回合限触发一次)。"..
  "<br>〖踏阵〗:锁定技，当你造成伤害后，你可以令目标直到你的下回合开始前无法对你使用牌，然后你可偷取目标至多等同此次伤害量个技能(每回合限触发两次）。",
  ["$tshujl__doupo"] = "辕门射戟，天下无双。",
  ["$tshujl__tazheng"] = "人不为己，天诛地灭！",
}

local sajia = General(extension, "tshujl__sajia","hundun",0,0)
sajia.hidden = true





local chuangshi_active = fk.CreateActiveSkill{
  name = "#tshujl_chuangshi_active",
  card_num = 0,
  target_num = 0,
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  interaction = function()
    if Self:getMark("tshujl__chuangshi_choose") < 5 then
      return UI.ComboBox {choices = {"tshujl_chuangshi_random","tshujl_chuangshi_choose"}}
    else
      return UI.ComboBox {choices = {"tshujl_chuangshi_random"}}
    end
  end,
}
local chuangshi = fk.CreateTriggerSkill{
  name = "tshujl__chuangshi",
  anim_type = "masochism",
  global = true,
  priority = 11,
  frequency = Skill.Compulsory,
  events = {fk.TurnStart,fk.Damaged},
  can_trigger = function(self, event, target, player, data)
  if player.dead then return false end
    return target == player and player:getMark("tshujl__sajia") > 0 and math.random(1,10) <= 9 and player:usedSkillTimes(self.name, Player.HistoryTurn) < 2
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    if player.id > 0 and player:getMark("tshujl__chuangshi_choose") < 5 then
    local n =  player:getMark("tshujl__chuangshi_choose") or 0
    n = 5 - n
      local _, ret = room:askForUseActiveSkill(player,"#tshujl_chuangshi_active", "创世：你可以重新从七张武将牌中获得并立即触发一个技能(剩 "..n.." 次自选机会)。", true)
      if ret then
        self.cost_data = ret.interaction
        return true
      end
    else
      self.cost_data = "tshujl_chuangshi_random"
      return room:askForSkillInvoke(player,self.name,nil,"创世：你可以重新从七张武将牌中获得并立即触发一个技能。")
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local gens = {}
    local all = Fk:getAllGenerals()
    if self.cost_data == "tshujl_chuangshi_choose" then
      room:addPlayerMark(player,"tshujl__chuangshi_choose",1)
      local cgens = table.random(all,6)
      local ask = {}
      for _, g in ipairs(cgens) do
        table.insert(ask,g.name)
      end
      gens = room:askForGeneral(player,ask,3,false)
    elseif self.cost_data ==  "tshujl_chuangshi_random" then
      local cgens = table.random(all,7)
      for _, g in ipairs(cgens) do
        table.insert(gens,g.name)
      end
    end
    local black = {"jbsao__wuyaowang","jbs_sairen","zuoci","os__zhaoxiang","zhaoxiang","ol_ex__zuoci","buqun__ailing","starsp__xiahoudun"}
    local wt = table.simpleClone(gens)
    for _, g in ipairs(wt) do
      if Fk.generals[g].package.extensionName == "tshu" or table.contains(black,g)   then
        table.removeOne(gens,g)
      end
    end
    if #gens <= 0 then  room:doBroadcastNotify("ShowToast","请不要选择禁将。") return end
      local skills = {}
      local choices = {}
      for _, general_name in ipairs(gens) do
        local general = Fk.generals[general_name]
        local g_skills = {}
        for _, skill in ipairs(general.skills) do
            table.insertIfNeed(g_skills, skill.name)
        end
        for _, s_name in ipairs(general.other_skills) do
          local skill = Fk.skills[s_name]
            table.insertIfNeed(g_skills, skill.name)
        end
        table.insertIfNeed(skills, g_skills)
        if #choices == 0 and #g_skills > 0 then
          choices = {g_skills[1]}
        end
      end
      if #choices > 0 then
        local result = player.room:askForCustomDialog(player, self.name,
        "packages/tianshu/qml/ChooseGeneralSkillsBox2.qml", {
          gens, skills,1,1, "#tshujl_chuangshi-choice",true
        })
        if result == "" and player.id < 0 then
          local h = table.random(skills)
          choices = table.random(h,1)
        else
          result = string.gsub(result, "'", '"')
          choices = json.decode(result)
        end
        

        if (result ~= "" or player.id < 0 )and #choices > 0 then
          local mark = player:getTableMark(self.name)
          room:setPlayerMark(player,self.name,{})
          if #mark > 0 then
            room:handleAddLoseSkills(player, "-"..table.concat(mark, "|-"), nil,false)
          end
          
        local mark = player:getTableMark(self.name)
        for _, sk in ipairs({choices}) do
          table.forEach(sk, function(s) if not player:hasSkill(s) then table.insertIfNeed(mark,s) end end)
        end
        room:setPlayerMark(player,self.name,mark)
        room:handleAddLoseSkills(player, table.concat(choices, "|"), nil,false)
        local tskills = {}
        local s2 = Fk.skills[choices[1]]
      table.insertIfNeed(tskills,s2)
      for _, s3 in ipairs(s2.related_skills) do
        table.insertIfNeed(tskills,s3)
      end
        for _, s in ipairs(tskills) do
          if s:isInstanceOf(TriggerSkill) and type(s.events) == "table" and (table.contains(s.events,fk.GameStart) or table.contains(s.events, fk.GamePrepared)) then
            local events = {fk.GamePrepared, fk.GameStart}
            for i = #events, 1, -1 do
              if not table.contains(s.events, events[i]) then
                table.remove(events, i)
              end
            end
            for _, e in ipairs(events) do
              if s:triggerable(e, player, player, nil) then
                s:trigger(e, player, player, nil)
              end
            end
          elseif s:isInstanceOf(ActiveSkill) and player:hasSkill(s.name) then
            room:askForUseActiveSkill(player,s.name,"是否发动技能 "..Fk:translate(s.name).." ？",true)
            --[[
          elseif s:isInstanceOf(TriggerSkill) and type(s.events) == "table" and player:hasSkill(s.name) then
            local e = s.events
            local be = {fk.GamePrepared,fk.GameStart,fk.CardResponding,fk.CardUseFinished,fk.CardUsing,fk.CardEffectCancelledOut,fk.CardRespondFinished,fk.CardEffectFinished,fk.CardEffecting,fk.DrawNCards,fk.BeforeDrawCard}
            for _, b in ipairs(be) do
              table.removeOne(e,b)
            end
            if #e > 0 then
              room:useSkill(player,s, function()
                return s:use(table.random(e), player, player)
              end)
            end
          ]]
          end
        end
        end
      end
  end
}



local mieshi = fk.CreateTriggerSkill{
  name = "tshujl__mieshi",
  anim_type = "offensive",
  global = true,
  priority = 11,
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
  if player.dead then return false end
    if event == fk.TargetSpecified then
      return target == player  and player:getMark("tshujl__sajia") > 0 and math.random(1,10) <= 8 and not data.card.is_damage_card and not player.dead and data.firstTarget and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 
    end
  end,
  on_cost = function (self, event, target, player, data)
    local tars = AimGroup:getAllTargets(data.tos)
    table.removeOne(tars,player.id)
    if #tars <= 0 then return end
    local to = player.room:askForChoosePlayers(player,tars, 1, 1, "灭世：选择其中一个目标令其本回合无法使用、打出手牌或至多两个技能失效。", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    local choices = {"技能失效","禁用手牌"}
    local choice = room:askForChoice(player,choices,self.name,"灭世：选择要对 "..Fk:translate(to.general).." 进行的操作。")
    if choice == "技能失效" then
      local skills = {}
      for _, s in ipairs(to.player_skills) do
        if not (s.attached_equip or s.name[#s.name] == "&"  or string.sub(s.name, 1,1) == "#") then
          table.insert(skills,s.name)
        end
      end
      if #skills < 1 then return end
      local gskills = T.choosemarkskillask(player,skills,room,1,2,"选择 "..Fk:translate(to.general).." 的至多两个技能失效")
      if not (gskills and #gskills >= 1) then 
        gskills = table.random(skills,2) 
      end
      local mark = type(to:getMark("@@"..self.name.."-turn")) == "table" and to:getMark("@@"..self.name.."-turn") or {}
      table.insertTableIfNeed(mark,gskills)
      room:setPlayerMark(to,"@@"..self.name.."-turn",mark)
    elseif choice == "禁用手牌" then
      room:setPlayerMark(to,"@@"..self.name.."2-turn",1)
    end
  end,
}
local mieshi_trigger = fk.CreateTriggerSkill{
  name = "#tshujl__mieshi_trigger",
  anim_type = "offensive",
  global = true,
  priority = 0.5,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
  if player.dead then return false end
    return target == player  and player:getMark("tshujl__sajia") > 0 and data.to and data.to ~= player and math.random(1,10) <= 8 and data.to.hp > data.damage and
      player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "灭世：是否令对 "..Fk:translate(data.to.general).." 造成的伤害等同于其体力值？")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(mieshi.name)
    data.damage = data.to.hp
  end,
}
local mieshi_skill = fk.CreateInvaliditySkill {
  name = "#tshujl__mieshi_skill",
  global = true,
  priority = 15,
  invalidity_func = function(self, from, skill)
    local zb = type(from:getMark("@@"..mieshi.name.."-turn")) == "table" and from:getMark("@@"..mieshi.name.."-turn") or {}
      return table.contains(zb,skill.name)
  end
}
local mieshi_prohibit = fk.CreateProhibitSkill{
  name = "#tshujl__mieshi_prohibit",
  global = true,
  prohibit_use = function(self, player, card)
    if player:getMark("@@"..mieshi.name.."2-turn") > 0 then
      local cardlist = Card:getIdList(card)
      return #cardlist > 0 and table.every(cardlist, function(id)
        return table.contains(player:getCardIds(Player.Hand), id)
      end)
    end
  end,
  prohibit_response = function(self, player, card)
    if player:getMark("@@"..mieshi.name.."2-turn") > 0 then
      local cardlist = Card:getIdList(card)
      return #cardlist > 0 and table.every(cardlist, function(id)
        return table.contains(player:getCardIds(Player.Hand), id)
      end)
    end
  end,
}
local matai = fk.CreateTriggerSkill{
  name = "tshujl__matai",
  mute = true,
  global = true,
  priority = 11,
  frequency = Skill.Compulsory,
  events = {fk.Deathed,fk.DamageInflicted,fk.PreHpLost},
  can_trigger = function(self, event, target, player, data)
    if event == fk.DamageInflicted or event == fk.PreHpLost then
      return target == player and player:getMark("@@"..self.name.."-turn") > 0
    elseif event == fk.Deathed then
      return target == player and player:getMark("tshujl__sajia") > 0 and player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and player:getMark(self.name) == 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.DamageInflicted or event == fk.PreHpLost then
      room:notifySkillInvoked(player,self.name,"drawcard")
      player:broadcastSkillInvoke(self.name)
      return true
    elseif event == fk.Deathed then
      room:notifySkillInvoked(player,self.name,"big")
      player:broadcastSkillInvoke(self.name)
      room:notifySkillInvoked(player,self.name,"support")
      room:revivePlayer(player, false)
      room:setPlayerMark(player,"@@"..self.name.."-turn",1)
      if player.maxHp < 1 then return end
      room:changeMaxHp(player,3)
      room:setPlayerProperty(player, "hp", player.maxHp)
      player:drawCards(5,self.name)
      room:setPlayerMark(player,self.name,1)
    end
  end,
  refresh_events = {fk.GameOverJudge,fk.BuryVictim},
  can_refresh = function (self, event, target, player, data)
    return target == player  and player:getMark("tshujl__sajia") > 0 and player.maxHp > 0 and player:usedSkillTimes(self.name, Player.HistoryGame) == 0 
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    return
  end,
}
mieshi:addRelatedSkill(mieshi_trigger)
mieshi:addRelatedSkill(mieshi_prohibit)
mieshi:addRelatedSkill(mieshi_skill)
chuangshi:addRelatedSkill(chuangshi_active)
sajia:addSkill(chuangshi)
sajia:addSkill(mieshi)
sajia:addSkill(matai)
Fk:loadTranslationTable{
  ["tshujl__sajia"] = "撒迦",

  ["tshujl__chuangshi"] = "创世",
  [":tshujl__chuangshi"] = "锁定技，你的回合开始时或当你受到伤害后，你有90%概率可以重新从7张武将牌(5次自由选将机会)中获得其中一个技能,若为主动技或游戏开始时机可发动的技能则立即触发一次,获得新技能的同时会失去上次以此法获得的技能（每回合限触发两次）。",

  ["#tshujl_chuangshi-choice"] = "创世：选择获得1个技能,或保留上次技能。",
  ["tshujl_chuangshi_random"] = "随机武将",
  ["tshujl_chuangshi_choose"] = "自选武将",
  ["#tshujl_chuangshi_active"] = "创世",
  ["#tshujl__mieshi_trigger"] = "灭世",
  ["#tshujl__mieshi_prohibit"] = "灭世",
  ["#tshujl__mieshi_skill"] = "灭世",
  ["@@tshujl__mieshi-turn"] = "灭世:技能失效",
  ["@@tshujl__mieshi2-turn"] = "灭世:禁用手牌",
  
  ["tshujl__mieshi"] = "灭世",
  [":tshujl__mieshi"] = "锁定技，你使用非伤害类牌指定其他角色为目标时，有80%概率可以令其中一个目标本回合至多两个技能失效或无法使用、打出手牌（此项每回合限触发一次）；当你对其他角色造成伤害时，有80%概率可以令此次伤害量等同受伤目标当前体力值（此项每回合限触发一次）。",
  ["#tshujl__mieshi-invoke"] = "灭世：你可以令你对 %arg 造成的伤害等同于其体力值。",
  ["tshujl__matai"] = "马太",
  [":tshujl__matai"] = "锁定技，你死亡后立即复活，然后免疫所有伤害与体力流失直到本回合结束（每局游戏限触发一次）。",
  ["@@tshujl__matai-turn"] = "马太福音",
  [":tshujl__sajia"] = "<br>〖创世〗:锁定技，你的回合开始时或当你受到伤害后，你有90%概率可以从7张武将牌(5次自由选将机会)中获得其中一个技能,若为主动技或游戏开始时机可发动的技能则立即触发一次，获得新技能的同时会失去上次以此法获得的技能（每回合限触发两次）。"..
  "<br>〖灭世〗:锁定技，你使用非伤害类牌指定其他角色为目标时，有80%概率可以令其中一个目标本回合至多两个技能失效或无法使用、打出手牌（此项每回合限触发一次）；当你对其他角色造成伤害时，有80%概率可以令此次伤害量等同受伤目标当前体力值（此项每回合限触发一次）。"..
  "<br>〖马太〗:锁定技，你死亡后立即复活，然后免疫所有伤害与体力流失直到本回合结束（每局游戏限触发一次）。",

  ["$tshujl__chuangshi1"] = "我创造，我毁灭，我就是上帝。",
  ["$tshujl__chuangshi2"] = "再给我讲讲快乐王子的故事吧，弥赛亚。",
  ["$tshujl__chuangshi3"] = "弥赛亚，不要把我给你的金子给别人。",
  ["$tshujl__mieshi1"] = "以后，你就是上帝的仆人了。",
  ["$tshujl__mieshi2"] = "龙角、尾巴、辫子，这三个地方不能碰。",
  ["$tshujl__matai1"] = "Twinkle twinkle little star~<br>额..咳，你什么都没听到。",
  ["$tshujl__matai2"] = "一个冬天就够了？我可以陪你一个四季。",
}




return extension